How to detect the length of an integer? in case i had le: int test(234567545);
how do i know how long the int is? like telling me there is 9 numbers inside it???
i have tried :
// assign directly to a string.
sprintf(buffer_length, "%d\n", 234567545);
string sf = buffer_length;
cout <<sf.length()-1 << endl;
How about division:
int length = 1; int x = 234567545; while ( x /= 10 ) length++;
or use the
log10 method from
log10 returns a
double, so you'll have to adjust the result.