SFML community forums

Help => General => Topic started by: neml on May 03, 2015, 08:50:27 pm

Title: Convert user input to integer (SFML 2.0)
Post by: neml 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?
Title: Re: Convert user input to integer (SFML 2.0)
Post by: G. 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.
Title: Re: Convert user input to integer (SFML 2.0)
Post by: Laurent 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.
Title: Re: Convert user input to integer (SFML 2.0)
Post by: neml 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