+ 1

C++ Conversions?

So I need to turn an int into a string in c++. Is this possible?

1st Nov 2018, 3:09 AM
Daniel Cooper
Daniel Cooper - avatar
2 Answers
+ 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/
1st Nov 2018, 3:20 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 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)"..
1st Nov 2018, 4:01 AM
Mensch
Mensch - avatar