SFML community forums

Help => Graphics => Topic started by: MarcuzPwnz on February 08, 2013, 04:30:12 am

Title: [Simple] How to output an integer on the screen as Text
Post by: MarcuzPwnz on February 08, 2013, 04:30:12 am
How would I set an sf::Text to hold an int variable so when I draw the Text to the screen it would output my integer, the reason I don't want to just set it to a String that stores "1" is because I want to be able to change and display new values stored in this Text.

I have read the documentation of the sf::Text class and had a play around with the Text class in my IDE and still haven't figured this out.

Would anyone be able to help me out? Thanks. :)
Title: Re: [Simple] How to output an integer on the screen as Text
Post by: eXpl0it3r on February 08, 2013, 04:40:03 am
This is a basic C++ problem and has nothing really to do with SFML.
If you want to convert a number to a string, you can use std::to_string with C++11 or make use of a stringstream:
#include <sstream>
// ...
std::stringstream ss;
ss << 12;
sf::Text.setString(ss.str());
Title: Re: [Simple] How to output an integer on the screen as Text
Post by: MarcuzPwnz on February 08, 2013, 04:47:14 am
I didn't really know what the fix was, it could have been some SFML function that I didn't know about.

Thanks for the response thought, much appreciated. :)
Title: Re: [Simple] How to output an integer on the screen as Text
Post by: eXpl0it3r on February 08, 2013, 04:58:14 am
I didn't really know what the fix was, it could have been some SFML function that I didn't know about.
It's not a 'fix', it's a general programming problem. For instance google: converting int to string
And then add whatever programming language you want to the end and you'll get hundreds of answers for each programming language. ;)

With that said a simple 'convert int to string c++' would've already given you the answer... ::)