SFML community forums

Help => General => Topic started by: Aquacalvin on March 18, 2014, 01:55:04 am

Title: Problem With Text
Post by: Aquacalvin on March 18, 2014, 01:55:04 am
Hey everyone! Is there any way to print integer variables through sf::Text? If I can't, is there another way to accomplish my goal? Thanks.
Calvin
Title: Re: Problem With Text
Post by: didii on March 18, 2014, 02:45:28 am
There are many solutions to your problem. Just search Google for integer to string conversions. Here (http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html) is a list of methods with their respective speed.
Title: Re: Problem With Text
Post by: math1992 on March 18, 2014, 02:46:28 am
There exist a C function to convert an iteger into a char*, but most of the c++ compiler do not support it.

Try this following code to see if it is defined:

#include <stdio.h>
#include <stdlib.h>

using namespace std;

string Text;
itoa( 10, Text, 10 );

 

If your compilator says that it does not recognize itoa then you will have to write your own function.

Edit:
Or use those proposed by didii :P
Title: Re: Problem With Text
Post by: Jesper Juhl on March 18, 2014, 07:38:55 am
Use std::to_string : http://en.cppreference.com/w/cpp/string/basic_string/to_string
or pick something from didii's list.
Title: Re: Problem With Text
Post by: Peteck on March 18, 2014, 11:54:27 pm
Like Jesper said, use the std::to_string.

sf::Text text;
sf::String str = std::to_string(123);

//add font and stuff

text.setString(str);