Printing numbers in Allegro

Started by
2 comments, last by pi_man 16 years, 6 months ago
i've been having a bit of trouble with printing numbers in Allegro. At the moment i am using the textout_ex() function and replacing the string with a variable holding the number of lives the player has left, problem being it says "invalid conversion from `int' to `const char*'" Any help would be great.
Advertisement
You need to convert the number to a string. Assuming C++, you can use a std::stringstream or boost::lexical_cast. Ex:
std::stringstream sstr;sstr << my_number;const char * my_number_as_char_pointer = sstr.str().c_str()
The textprintf_ex() function provides printf style formatting, so doing any of your own conversion is a wasted effort.

int player_score;textprintf_ex(screen, font, 10, 10, makecol(255, 100, 200), -1, "Score: %d", player_score);
Ok Thanks guys, that looks like it will work perfectly. Will try it out tonight.

This topic is closed to new replies.

Advertisement