TextOut()

Started by
3 comments, last by Evil Steve 19 years, 6 months ago
y0 I'm using C++ and am wanting to output the score of player one and player two. The players each have their own class and in the class is the declaration "int score;" and in the constructor it's set to 0. I want to know how i could display their score with the TextOut() function? I know how to output strings and the like but outputting integers? and what about a string and an integer?...
Advertisement
You can only output a string. If you want an integer or anything else, you need to make it into a string first. For example:
char szBuffer[256];int nScore = 42;sprintf(szBuffer,"Player One: %d points",nScore);TextOut(hDC,0,0,szBuffer,strlen(szBuffer));

Use a function called:
itoa

Do something like,

char buffer[80];
int score = 24;
itoa(score, buffer, 10);

Look up the function in MSDN for reference

-prowst
Thanks alot.

In the itoa() func. what is the last value used for?
Thats the radix (base). 10 = base 10 (decimal). You can use it to output in binary if you set the radix to 2, or hex if you set it to 16, and so on.

This topic is closed to new replies.

Advertisement