Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Simple] How to output an integer on the screen as Text  (Read 4458 times)

0 Members and 2 Guests are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
[Simple] How to output an integer on the screen as Text
« 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. :)
« Last Edit: February 08, 2013, 04:39:01 am by MarcuzPwnz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: [Simple] How to output an integer on the screen as Text
« Reply #1 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());
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: [Simple] How to output an integer on the screen as Text
« Reply #2 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. :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: [Simple] How to output an integer on the screen as Text
« Reply #3 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... ::)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything