I'm not retarded or anything, although I wouldn't say I'm the new to the SDL API. I kinda skimmed through my book, and seemingly read bits and pieces. I stopped for about a week and trying to get dedicated again.
Anyways, I've been viewing some shit online and in my book, and wanted to try something with the TTF fonts extension for libsdl. Anyone know how to show an integer along with the text it actually shows?
An int is obviously not a string. Having said that, numeric to string/string to numberic is a royal pain in the ass for something seemingly so easy. Generally it works something like this. Note that it's for a std::string and I'm almost certain.
Note that it returns a string of type std::string instead of the needed type of const char *. Construct your string you want to use for the font in with a std::string then use string.c_str() to get a const char * type.
Atleast, this is how I think it works!
Last edited by Live-Dimension on Tue May 11, 2010 7:09 am, edited 1 time in total.
GyroVorbis wrote:I always favor the C method to the C++ method in this scenario. With C++ you're going from a string stream, to a C++ string ,to a C string.
GyroVorbis wrote:I always favor the C method to the C++ method in this scenario. With C++ you're going from a string stream, to a C++ string ,to a C string.
char buffer[200];
sprintf(buffer, "The number is: %d", number);
text = TTF_RenderText_Solid( font, buffer, textColor );
That's quite a bit prettier.
If you're writing this in C (rather than C++), you don't have a choice either.
That function is located in "stdio.h"
i like this was better as well, but id make char buffer[200] to char buffer[11] 32bit int or [21] 64bit int.
ps: i might be off by one or so, just quickly did it in my head. and i know you just used 200 since thats kinda a number you see alot in examples to avoide confusion about why 11 and what not, that and 80(console width i think),
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
I agree, simple number conversion isn't the strength of stringstream. But it is flexible and scalable. And you have an abstraction from the actual buffer (and it's size). In this scenario every method is fine.