Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Integer [?]

Tags:

c++

In Java, strings have a charAt() function.

In C++, that function is simply stringname[INDEX]

However, what if I wanted to use a particular number at a certain index of an integer?

E.g.

int value = 9123;

Let's say I wanted to work with the index 0, which is just the 9.

Is there a way to use index at's with integers?

like image 469
Edge Avatar asked Nov 27 '22 03:11

Edge


1 Answers

int value = 9123;
std::stringstream tmp;
tmp << value;
char digit = (tmp.str())[0];
like image 73
Andreas Brinck Avatar answered Dec 08 '22 22:12

Andreas Brinck