C++ 如何将 Int 转换为 CString?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12602526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I convert an Int to a CString?
提问by Java Player
I can convert a Double
to a CString
using _ecvt
我可以将 a 转换Double
为 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
?
那么,有没有像上面那样将 an 转换int
为 的方法CString
?
回答by dsgriffin
Here's one way:
这是一种方法:
CString str;
str.Format("%d", 5);
In your case, try _T("%d")
or L"%d"
rather than "%d"
在你的情况下,尝试_T("%d")
或L"%d"
而不是"%d"
回答by snowdude
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:
如果您想要更类似于您的示例的内容,请尝试 _itot_s。在 Microsoft 编译器上,_itot_s 指向 _itoa_s 或 _itow_s,具体取决于您的 Unicode 设置:
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.
它应该稍微快一点,因为它不需要解析输入格式。