Writing two variables to one string.
Hey, i was wondering if you could tell me a way to take two variables and turn them into a string.
For example take two variables:
char v1[25];
int v2;
And say v1 was "Blabla".
And say v2 was 100.
How would i put both of them in a new string,
So the new string would be:
"Blablah 100".
Thanks for your help,
Zido.
In C++ I would use a std::stringstream.
std::stringstream sstr;sstr << v1 << " " << v2;std::string new_string = sstr.str();
In C you could use snprintf():
char buffer[some_size];snprintf(buffer, some_size - 1, "%s %d", v1, v2);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement