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

Author Topic: SFML Intenger to sf::String?  (Read 3189 times)

0 Members and 1 Guest are viewing this topic.

Raidenkk

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML Intenger to sf::String?
« on: December 26, 2011, 03:27:55 am »
Hey,
how can transform my Intenger Variable to a sf::String?

My example:
  int Level = 5;
 
  sf::String String;
  String.SetText (Level);

minirop

  • Sr. Member
  • ****
  • Posts: 254
    • View Profile
    • http://dev.peyj.com
SFML Intenger to sf::String?
« Reply #1 on: December 26, 2011, 04:01:27 am »
Before C+11 : std::ostringstream
Since C+11 : std::to_string

Raidenkk

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML Intenger to sf::String?
« Reply #2 on: December 26, 2011, 05:42:52 am »
I mean sf::String not the normal string.
I will my Intenger to sf::String transform.

String.SetText (Level);
is not so...

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
SFML Intenger to sf::String?
« Reply #3 on: December 26, 2011, 10:48:58 am »
Convert the int first to std::string, then it is automatically converted to sf::String. Just look at the constructors of the latter.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
SFML Intenger to sf::String?
« Reply #4 on: December 26, 2011, 04:14:06 pm »
I just tried to compile a code using std::to_string with GCC 4.6.1 (c++11 enabled) and It seems to be not included in the <string> header (I got an error telling me that) ! :s

Do you have an idea for that ?
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

minirop

  • Sr. Member
  • ****
  • Posts: 254
    • View Profile
    • http://dev.peyj.com
SFML Intenger to sf::String?
« Reply #5 on: December 26, 2011, 05:02:05 pm »
Quote from: "Zinlibs"
Do you have an idea for that ?

just looked in my headers (mngw 4.5.2), and I have them in bits/basic_string (included by string) with the condition :
Quote
#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
     && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))

you used -std=c++11 ? and what about -std=c++0x ?

Raidenkk

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML Intenger to sf::String?
« Reply #6 on: December 26, 2011, 05:43:54 pm »
How become the String in my sf::string

Code: [Select]
// Level
std::string sString_Level( int Spieler_Level );
sf::String String_Level;
String_Level.SetFont (Font_Naruto);
String_Level.SetPosition (310,115);
String_Level.SetSize (20);
String_Level.SetColor (sf::Color::Yellow);

switch (Spieler_Level)
{
case 1:
{
String_Level.SetText ("TEST");
} break;
}
App.Draw (String_Level);

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
SFML Intenger to sf::String?
« Reply #7 on: December 26, 2011, 09:12:55 pm »
I looked in bits/basic_string and I found the same condition.
I'm already using -std=c++0x flag. I tried -std=c++11 with no success.
Here is my code, but I think this is correct :

Code: [Select]
#include<string>

int n = 8;
std::string s = std::to_string(n);
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
SFML Intenger to sf::String?
« Reply #8 on: December 27, 2011, 12:47:35 am »
Quote from: "Raidenkk"
How become the String in my sf::string
Please, inform yourself at least 20 seconds before you ask everything. Look at the documentation of sf::String, and there at the constructors. By the way, I already gave you the answer to this question in my last post.

Quote from: "Zinlibs"
Here is my code, but I think this is correct
Yes, it is. It might be that std::to_string() is not fully supported with the default options. Visual Studio 2010 doesn't support it either (actually it would, but they forgot the most important overloads :x), so using it compiler-independently is not possible yet anyway.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Raidenkk

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML Intenger to sf::String?
« Reply #9 on: January 02, 2012, 03:59:57 pm »
Hey i have test it andy my Compiller says no. why?

Code: [Select]
int test = 32;
std::string sString_Spieler_Level = std::to_string(test); // <---fail

sf::String String_Level;
String_Level.SetFont (Font_Naruto);
String_Level.SetPosition (310,115);
String_Level.SetSize (20);
String_Level.SetColor (sf::Color::Yellow);
String_Level.SetText (sString_Spieler_Level);

 

anything