我可以将 a 转换Double
为CString
using_ecvt
result_str=_ecvt(int,15,&decimal,&sign);
那么,是否有一种像上面那样将转换为的int
方法CString
?
我可以将 a 转换Double
为CString
using_ecvt
result_str=_ecvt(int,15,&decimal,&sign);
那么,是否有一种像上面那样将转换为的int
方法CString
?
这是一种方法:
CString str;
str.Format("%d", 5);
在你的情况下,尝试_T("%d")
或L"%d"
而不是"%d"
如果您想要更类似于您的示例的内容,请尝试 _itot_s。在 Microsoft 编译器上,_itot_s 指向 _itoa_s 或 _itow_s,具体取决于您的 Unicode 设置:
CString str;
_itot_s( 15, str.GetBufferSetLength( 40 ), 40, 10 );
str.ReleaseBuffer();
它应该稍微快一些,因为它不需要解析输入格式。
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;
}