SFML community forums
Help => Graphics => Topic started by: tpih on December 19, 2011, 09:46:00 am
-
I have searched around google but found nothing. How do I print variables to the screen? I have a score that I would like the user to be able to see.
Thanks
-
The question is not how to draw numbers on screen, but rather how to convert your numbers to strings that you can draw with SFML.
-> Google "c++ int to string" ;)
-
Can be as easy as:
char out[16];
int score = 5;
sprintf(out, "Score: %i", score)
sf::Text text(out);
renderWindow.Draw(text);
-
Nop, this code is C and unsafe.
There's only one good solution (with the current standard and no third-party libraries):
#include <sstream>
std::ostringstream oss;
oss << score;
sf::Text text(oss.str());
-
If your compiler supports C++11, you can simply use the to_string function.