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

Author Topic: Problem With Text  (Read 1804 times)

0 Members and 1 Guest are viewing this topic.

Aquacalvin

  • Newbie
  • *
  • Posts: 21
    • View Profile
Problem With Text
« 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

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Problem With Text
« Reply #1 on: March 18, 2014, 02:45:28 am »
There are many solutions to your problem. Just search Google for integer to string conversions. Here is a list of methods with their respective speed.

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Problem With Text
« Reply #2 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

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Problem With Text
« Reply #3 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.
« Last Edit: March 18, 2014, 07:40:41 am by Jesper Juhl »

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Problem With Text
« Reply #4 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);