Simple TextOut of a variable?

How would I do something like this:

int guesses;
TextOut(hdc, 150, 60, TEXT(guesses),2);

I want to output a variable in to my screen. How would I do that?
std::cout <<variable;
This works in a windows project? I dont see it appearing in the window anywhere? That function has no paramters for a dimension either...?

Is there no simple answer to this?
Last edited on
How exactly did you learn C++ without learning about the standard I/O functions?
http://www.cplusplus.com/doc/tutorial/basic_io/
Yes :) I understand how cout works. I have been working with the DOS window for a while and now I am moving on to the windows application.

I am using graphics now and the simple i/o functions no longer appear. I have programmed a simple matching game and I am trying to output the player's scores on the screens.

The only way I have found I can do thi so far is by having a bunch of if statements like:

TextOut(hdc, 150, 750, TEXT("Player 1:"),9);
if (player1_score == 0)
TextOut(hdc, 220, 750, TEXT("0"),1);
if (player1_score == 1)
TextOut(hdc, 220, 750, TEXT("1"),1);
if (player1_score == 2)
TextOut(hdc, 220, 750, TEXT("2"),1);
if (player1_score == 3)
TextOut(hdc, 220, 750, TEXT("3"),1);

However - this seems like a lot of unnecessary code. I want to somehow output player1_score instead of all of these hardcoded strings.

Oh, I see.

Try this:
std::stringstream stream;
stream <<player1_score;
stream.str().c_str(); //<-- Use this instead of TEXT(*). Note that if UNICODE is #defined, you'll have to use a std::wstringstream.
Is this what it is supposed to look like?

1
2
3
 basic_stringstream<int> stream;
	stream << player1_score;
	TextOut(hdc, 220, 750, stream.str().c_str() ,1);

I am getting a compiling error:

'TextOutW' : cannot convert parameter 4 from 'const int *' to 'LPCWSTR'

sorry if i seem dull. :(
No, it's supposed to look exactly or almost exactly like what I wrote.
Ok, it compiles, but where does it appear within the window? There are no coordinates to control where the output is displayed?
but where does it appear within the window?
Hell if I know. I just gave you the interface to convert integers to strings. How to use and where to pass the string is up to you.
Topic archived. No new replies allowed.