Jump to content
  • Advertisement
Sign in to follow this  
_Zido_

Writing two variables to one string.

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
In C++ I would use a std::stringstream.

std::stringstream sstr;
sstr << v1 << " " << v2;
std::string new_string = sstr.str();

Share this post


Link to post
Share on other sites
In C you could use snprintf():

char buffer[some_size];
snprintf(buffer, some_size - 1, "%s %d", v1, v2);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!