SFML(displaying a varible)

I apologize in advance, as i know this isnt the SFML forum, but Ive seen a good amount of forum goers that have knowledge of SFML. How would i display a varible on the screen that SFML creates? Say im trying to display the score on the screen after the player dies in a simple game. What code would i use? I know of the sf::String class, but doesnt it only display const pointer-to chars? Thanks for the help!
doesnt it only display const pointer-to chars


Just do any normal integer to string conversion. Assuming you're using SFML 1.6 (and not 2.0)

1
2
3
4
5
6
7
8
9
int score = 123456; // the score to print

sf::String mytext;
std::stringstream ss;  // #include <sstream>
ss << score;

mytext.SetText( ss.str().c_str() );

// draw 'mytext' to your window 
May i have a link to reference for that class? i have never heard of <sstream>, but id love to learn more about it.
It works just like cout, only it puts things in a string rather than to the display.

You then use '.str()' to get a std::string, and then .c_str() to get a char* from the string.


http://cplusplus.com/reference/iostream/stringstream/
Topic archived. No new replies allowed.