Sign in to follow this  
ecr0n

TextOut()

Recommended Posts

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?...

Share this post


Link to post
Share on other sites
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));


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this