itoa function problem

前端 未结 6 1147
北海茫月
北海茫月 2020-12-20 14:08

I\'m working on Eclipse inside Ubuntu environment on my C++ project.

I use the itoa function (which works perfectly on Visual Studio) and the compiler c

6条回答
  •  执念已碎
    2020-12-20 14:29

    itoa() is not part of any standard so you shouldn't use it. There's better ways, i.e...

    C:

    int main() {
        char n_str[10];
        int n = 25;
    
        sprintf(n_str, "%d", n);
    
        return 0;
    }
    

    C++:

    using namespace std;
    int main() {
        ostringstream n_str;
        int n = 25;
    
        n_str << n;
    
        return 0;
    }
    

提交回复
热议问题