visual c++: convert int into string pointer

前端 未结 10 2142
既然无缘
既然无缘 2021-01-22 09:01

how to convert integer into string pointer in visual c++?

10条回答
  •  面向向阳花
    2021-01-22 09:38

    This is how I did it in my homework since we were only allowed to use some predetermined libraries. I'm pretty sure it's not considered a "best practice" though ;)

    string int2string(int integer) {
        string str;
        int division = integer;
    
        while (division > 0) {
            str = char('0' + (division % 10)) + str;
            division = division / 10;
        }
    
        return str;
    }
    

提交回复
热议问题