Writing two variables to one string.

Started by
3 comments, last by _Zido_ 18 years, 8 months ago
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.
Advertisement
In C++ I would use a std::stringstream.
std::stringstream sstr;sstr << v1 << " " << v2;std::string new_string = sstr.str();
Im programming in c...
Any function for it in c?
In C you could use snprintf():
char buffer[some_size];snprintf(buffer, some_size - 1, "%s %d", v1, v2);
Okay, thanks. That would work.

This topic is closed to new replies.

Advertisement