C++ equivalent to the Python len() function? -


i have integer , need find out how many digits in it.

a little tricky handle negative numbers , case input zero:

int length(int n) {    int len = 0;    if (n < 0) { len = 1; n = -n; }    while (n > 9) {         n /= 10;         len++;    }    return len+1; } 

Comments

Popular posts from this blog

List<T>().Add problem C# -

Javascript natural sort array/object and maintain index association -