Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing variables

Status
Not open for further replies.

ebuBekir

Technical User
Sep 6, 2001
22
DE
Hi!
I need urgently a way to print out the variable of a variable into the main window. But how can I do this in MFC?
in Borland C, it was for example like,
int x = 10;
printf("%d",x);
Thanks for your help!
agurcan@hotmail.com
 
In MFC is a little bit more complicated.

in the OnDraw Method of your CView derived class write
CString myString = "Some text";
pDC->TextOut(xCoord,yCoord, myString).

If your variable is a member of your CDocument derived class, as it usually is you can access it through
GetDocument()->variable.

Hope this helps, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
I have tried the following, and even if I use
CString myString = (CString)(x);
it does not work. It just prints out one character and changes the character each time!
I can't understand it.

int x;

for (x=0;x<256;x++)
{
CString myString = x;
dc.TextOut( 600, 40, myString );
}
Thanks a lot for your help.:-Q
agurcan@hotmail.com
 
Yes, because you have left the coordinates where to print the caracters the same.

It will always print myString(which is one char) to the 400, 60 coordinates(from TextOut) overwritting the old ones.
You have to modify that values in the for loop, too.

Hope this helps, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top