C++ - how to find the length of an integer

后端 未结 13 1388
你的背包
你的背包 2020-12-09 10:03

I\'m trying to find a way to find the length of an integer (number of digits) and then place it in an integer array. The assignment also calls for doing this without the use

相关标签:
13条回答
  • 2020-12-09 10:41

    If you can use C libraries then one method would be to use sprintf, e.g.

    #include <cstdio>
    
    char s[32];
    
    int len = sprintf(s, "%d", i);
    
    0 讨论(0)
提交回复
热议问题