+ 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?

11th Feb 2022, 2:26 AM
Julio Amaro
Julio Amaro - avatar
4 Respostas
11th Feb 2022, 3:22 AM
CGM
CGM - avatar
+ 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
11th Feb 2022, 4:58 AM
saurabh
saurabh - avatar
+ 1
like int a=5; string s=to_string(a); cout<<s+"4"; it will print 54
11th Feb 2022, 4:56 PM
Mohammad al ayoubi
Mohammad al ayoubi - avatar