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

Author Topic: Convert user input to integer (SFML 2.0)  (Read 2428 times)

0 Members and 4 Guests are viewing this topic.

neml

  • Newbie
  • *
  • Posts: 2
    • View Profile
Convert user input to integer (SFML 2.0)
« on: May 03, 2015, 08:50:27 pm »
Hi guys! :)

I'm starting to develop my first game, and I need the user to enter his/her age before the game itself starts, as I need the age to calculate other game parameters.

The numbers entered are being stored in an sf::String, so that they can be displayed, but I don't know how to convert them from sf::String to int.

At first I thought about using an std::string and then converting to int with atoi, but I'm not sure I can display text if it's not of type sf::String :-\ .

Any ideas?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Convert user input to integer (SFML 2.0)
« Reply #1 on: May 03, 2015, 08:53:54 pm »
Converting your string into an int doesn't mean you can't keep it for display purpose.
You can have a string variable AND an integer variable.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Convert user input to integer (SFML 2.0)
« Reply #2 on: May 03, 2015, 08:54:30 pm »
sf::String is implicitly convertible to std::string. Then the std::string to int conversion is a trivial thing in C++, that you can easily learn to do with the help of Google.
Laurent Gomila - SFML developer

neml

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Convert user input to integer (SFML 2.0)
« Reply #3 on: May 03, 2015, 09:03:59 pm »
sf::String is implicitly convertible to std::string. Then the std::string to int conversion is a trivial thing in C++, that you can easily learn to do with the help of Google.

Thank you! I hadn't realized sf::String was convertible to std::string

 

anything