+ 1
How to turn an integer into a string?
I want to add an int to a string, I think I could do it if there is a way to convert the int in string and then add it. How could I do that?
4 Antworten
+ 4
I found this:
https://stackoverflow.com/a/8257728
And here I did the test:
https://code.sololearn.com/c8iXUzCONXRx/?ref=app
+ 2
Use inbuilt function `to_string(int x)` defined in 'string' library.
To learn more : https://en.cppreference.com/w/cpp/string/basic_string/to_string
+ 1
like
int a=5;
string s=to_string(a);
cout<<s+"4";
it will print 54