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
?
Solution 3. CString MyString; int MyInt; MyString. Format(L"%d",MyInt); Another way is to use the std library's to_wstring[^], and then cast the result to CString.
Converting a std::string to a CString is as simple as: std::string stdstr("foo"); CString cstr(stdstr. c_str()); This works for both UNICODE and MBCS projects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With