+ 1
C++ Conversions?
So I need to turn an int into a string in c++. Is this possible?
2 ответов
+ 4
int num = 12;
char chars[10];
itoa(num, chars, 10);
string str(chars);
cout << str;
https://code.sololearn.com/cV5J8x7qmSFV/?ref=app
You could use sprintf, if need to format the int number further.
References:
http://www.cplusplus.com/reference/string/string/string/
http://www.cplusplus.com/reference/cstdlib/itoa/
http://www.cplusplus.com/reference/cstdio/sprintf/
+ 2
You can use this👇👇
int x=10;
string s=to_string(x);
-if u want to store the string as an integer use "stoi(variable_name)"..