C++ 将 int 转换为 wstring

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14929791/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:50:06  来源:igfitidea点击:

convert int to wstring

c++stringtype-conversion

提问by l3utterfly

I want to convert an integer value (int) to std::wstring. What is the best way to do this? I'm developing for windows phone so I would rather avoid using external libraries (such as boost::lexical_cast). I'm looking for something simple, preferably one line of code that just assigns the int to the wstring.

我想将整数值 (int) 转换为 std::wstring。做这个的最好方式是什么?我正在为 Windows 手机开发,所以我宁愿避免使用外部库(例如 boost::lexical_cast)。我正在寻找一些简单的东西,最好是一行代码,只将 int 分配给 wstring。

Any help would be appreciated.

任何帮助,将不胜感激。

回答by Karthik T

Are you looking for std::to_wstring

你在找吗 std::to_wstring

std::wstring to_wstring( int value );   (since C++11)

Converts a signed decimal integer to a wide string with the same content as what std::swprintf(buf, sz, L"%d", value) would produce for sufficiently large buf.

将有符号十进制整数转换为宽字符串,其内容与 std::swprintf(buf, sz, L"%d", value) 为足够大的 buf 产生的内容相同。