I can convert a Double
to a CString
using _ecvt
result_str=_ecvt(int,15,&decimal,&sign);
So, is there a method like the one above that converts an int
to CString
?
This question is related to
c++
visual-c++
mfc
Here's one way:
CString str;
str.Format("%d", 5);
In your case, try _T("%d")
or L"%d"
rather than "%d"
If you want something more similar to your example try _itot_s. On Microsoft compilers _itot_s points to _itoa_s or _itow_s depending on your Unicode setting:
CString str;
_itot_s( 15, str.GetBufferSetLength( 40 ), 40, 10 );
str.ReleaseBuffer();
it should be slightly faster since it doesn't need to parse an input format.
Source: Stackoverflow.com