I thought this would be really simple but it's presenting some difficulties. If I have
std::string name = "John";
int age = 21;
How do I combine them to get a single string "John21"
?
I thought this would be really simple but it's presenting some difficulties. If I have
std::string name = "John";
int age = 21;
How do I combine them to get a single string "John21"
?
You can concatenate int to string by using the given below simple trick, but note that this only works when integer is of single digit. Otherwise, add integer digit by digit to that string.
The detailed answer is buried in below other answers, resurfacing part of it:
This is the easiest way:
There are more options possible to use to concatenate integer (or other numerric object) with string. It is Boost.Format
and Karma from Boost.Spirit (v2)
Boost.Spirit Karma claims to be one of the fastest option for integer to string conversion.