Assuming that you know you are outputting integers:
1 2 3 4 5
|
int turns = 10;
while (turns >= 0) {
TTF_RenderText_Solid(font, char(turns + '0') , textColor);
--turns;
}
|
Edit:
Actually, this is pretty bad =/. I knew it was bad, but then I realized the limitation of characters is '0' through '9'. Soooo bad.
What I have actually done in my own code is made a function that accepts an
std::string
for the text to output, two
int
s representing pixel positions on the screen, and an optional switch to center the text horizontally. The
std::string
has to then be converted to a C string, but I use them because they are so easy to work with. The function also interprets color codes imbedded within the text. I also keep track of a "cursor" to output paragraphs easily.
With this setup I just use:
1 2 3 4 5 6
|
template <typename T>
std::string itoa (T num) {
std::ostringstream ss;
ss << num;
return ss.str();
}
|
To convert numbers to
std::string
s.
The result of all this is much more flexibility:
1 2
|
int n = 5;
outputText(10, 10, "Number: " + itoa(n));
|
I actually would recommend doing something like this that works the way you want it as it is much more flexible and more easy to use. Not very difficult to set up either. =]