output to Screen Win32
I been looking for tutorials, but trust me when I say this. I can't even understand them, lots and lots of useless stuff they keep telling me to write and its not even what I want.
Anyone know how to do something like.
int x = 5;
cout << x;
of course this wont work because its Win32
Depends what you want. If you want the value to appear in a pop-up dialog, use a MessageBox. If you want the value to appear in the client area of your window, you need to use TextOut() inside handling a WM_PAINT message.
Either way, you need to put your value in a string, for which you want an ostringstream:
The above would require a non-UNICODE setting for the application BTW.
Either way, you need to put your value in a string, for which you want an ostringstream:
#include <sstream>using namespace std;void f(){ ostringstream os; int x=5; os << x; string s=os.str(); MessageBox(Hw,s.c_str(),"Output",MB_OK);}
The above would require a non-UNICODE setting for the application BTW.
I don't want a console application, I actually want a windows application.
EasilyConfused, what you gave me won't compile, are you sure its right or is it me thats messed up?
EasilyConfused, what you gave me won't compile, are you sure its right or is it me thats messed up?
#include <stdio.h> // For sprintf_sconst int MAX_TEXT = 100;char text [ MAX_TEXT ];int x = 5;sprintf_s ( text, "%i", x );MessageBox ( NULL, text, "Output", MB_OK );
Also, if you're using Visual Studio, be sure to set the Character Set to Multi-Byte in your project's properties. Hope this helps.
If it won't compile, the solution is not to abandon std::stringstream and use sprintf_n. One day, MAX_TEXT will come back and bite you in the bottom.
What errors does my snippet give?
As Darklighter says, you need to make sure UNICODE is not enabled for your project for the above to work.
What errors does my snippet give?
#include <string>#include <sstream>using namespace std;void f(HWND Hw) // the HWND to your main window{ ostringstream os; int x=5; os << x; string s=os.str(); MessageBox(Hw,s.c_str(),"Output",MB_OK);}
As Darklighter says, you need to make sure UNICODE is not enabled for your project for the above to work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement