Reputation: 31
Well in java with a string you can do this:
int stuff;
string otherstuff;
otherstuff = "I like this much stuff: " + stuff;
But in C++ I have no idea how to.
Upvotes: 1
Views: 593
Reputation: 2624
Also worth noting boost::lexical_cast<std::string>(stuff)
. If for some reason you can't use C++11
Upvotes: 1
Reputation: 19323
I like using stringstream for things like this.
std::stringstream ss;
double dub = 3.14159254;
ss << dub;
std::string s = ss.str();
Upvotes: 2
Reputation: 254431
In C++11:
otherstuff = "I like this much stuff: " + std::to_string(stuff);
Historically (and still sometimes useful in C++11):
std::ostringstream ss;
ss << "I like this much stuff: " << stuff;
otherstuff = ss.str();
Upvotes: 11