Tuesday, March 14, 2006

Small problem with a MFC application..

While I was coding with MFC with my C++ team mates Sally & Shimaa.. (we were doing the hacking task which was quite an easy one).. we faced a tiny silly problem... The problem was that when displaying an int value in a messagebox, the value appears as strange characters..

For example, if u wrote:
int x = 2;
CString str = x;

then u willl get strange characters in the Message box..
mmm.. I tried type casting.. (static_cast string str = <>(x); ) but.. the same thing happened again... I tried _itoa(x,str,size); ...but again & again.. it doesn't work well in all cases....actually I didn't knew how to fix it till I went home & googled for the solution... & here we go... just made good use of the "CString" class & everything went just fine... (Thanks Google)

I tried this Code as a sample:
int value = 1000;
CString string ;

IT WORKS.. :D ..

Here are some more additional information about the CString::Format method (got it from msdn )
nFormatID : The string resource identifier that contains the format-control string.
pszFormat :A format-control string.
argument :Optional arguments.

This function formats and stores a series of characters and values in the CStringT. Each optional argument (if any) is converted and output according to the corresponding format specification in pszFormat or from the string resource identified by nFormatID.

Just wanted to write this here in case anyone faced the same problem..
Still enjoying the MFC till now..
Meet u in another problem I face with programming ;)

No comments: