1
Graphics / Incrementing a number in a sf::String?
« on: October 17, 2010, 12:27:08 pm »
Just create a simple string converter class, like this:
and an example how to use it:
Code: [Select]
#include <sstream>
class StringConverter
{
public:
static int toInt(const std::string& str)
{
std::istringstream stream(str);
int value;
stream >> value;
return value;
}
static std::string toString(int value)
{
std::ostringstream stream;
stream << value;
return stream.str();
}
};
and an example how to use it:
Code: [Select]
int health = 100;
sf::String Text("Health: " + StringConverter::toString(health));