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
?
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
?
Here's one way:
CString str;
str.Format("%d", 5);
In your case, try _T("%d")
or L"%d"
rather than "%d"
_T
macro to match the LPCTSTR
parameter type. –
Highstepper _T("%d")
or L"%d"
rather than "%d"
. –
Highstepper 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.
template <typename Type>
CString ToCString (Type value)
{
return std::to_wstring (value).data ();
}
int main ()
{
const auto msg = ToCString (10);
std::wcout << msg.GetString () << std::endl;
return 0;
}
© 2022 - 2024 — McMap. All rights reserved.
cstring
tag is for the standard C++ headercstring
, not for Microsofts string thing. – Gallingitoa
is what you are looking for? – Baker