Int to string

In my game I would like to have a int (the lives the player has) and be able to change this number with my functions and then in each frame display the 'new' number. I haven't worked on the function to change the number yet.

Basically I would like to display the int on screen with SFML: sf::Text lives;

However, that requires the number to be a string. I was wondering how do I convert the int to a string so i can display it?
Last edited on
A couple of ways to do this:
1) If you want to use C-strings, itoa can be used.
http://www.cplusplus.com/reference/cstdlib/itoa/

2) You can also do this using stringstream
http://www.cplusplus.com/reference/sstream/stringstream/?kw=stringstream
1
2
3
4
 
  stringstream ss;
  ss << num_lives;  // int value
  lives = ss.str();      // assumes sf::Text derives from std::string 


Thank you for your response

I did exactly what you said for number 2 and it worked (with my own variables of course)

Thank you Anon, glad to see your still helping out. Same as a few years ago when before I had my break from coding :)
Last edited on
Topic archived. No new replies allowed.