In C++03, as other people have mentioned, you can use the ostringstream
type, defined in <sstream>
:
std::ostringstream stream;
stream << "Mixed data, like this int: " << 137;
std::string result = stream.str();
In C++11, you can use the std::to_string
function, which is conveniently declared in <string>
:
std::string result = "Adding things is this much fun: " + std::to_string(137);
Hope this helps!