如何在visualc++; 有人能解释C++中如何将单词转换成字符串吗? typedef struct _appversion { WORD wVersion; CHAR szDescription[DESCRIPTION_LEN+1]; } APPVERSION; // Some code APPVERSION AppVersions; // At this point AppVersions structure is initialized properly. string wVersion; wVersion = AppVersions.wVersion; // Error // Error 1 error C2668: 'std::to_string' : ambiguous call to overloaded function wVersion = std::to_string((unsigned short)AppVersions.wVersion); VisualC++环境中的< > >代码> Word < /C> >是未签名短 >的类型定义。< /P>
因此,您可以使用如何在visualc++; 有人能解释C++中如何将单词转换成字符串吗? typedef struct _appversion { WORD wVersion; CHAR szDescription[DESCRIPTION_LEN+1]; } APPVERSION; // Some code APPVERSION AppVersions; // At this point AppVersions structure is initialized properly. string wVersion; wVersion = AppVersions.wVersion; // Error // Error 1 error C2668: 'std::to_string' : ambiguous call to overloaded function wVersion = std::to_string((unsigned short)AppVersions.wVersion); VisualC++环境中的< > >代码> Word < /C> >是未签名短 >的类型定义。< /P>,c++,visual-c++,C++,Visual C++,因此,您可以使用std::to_string执行此任务: wVersion = std::to_string(AppVersions.wVersion); 编辑: Visual Studio 2010显然不完全支持C++11功能,请改用std::stringstream: std::stringstream stream; stream <<AppVersions.wVersion; wVersion = stream.str(); std::stringstream; s
std::to_string
执行此任务:
wVersion = std::to_string(AppVersions.wVersion);
编辑:
Visual Studio 2010显然不完全支持C++11功能,请改用std::stringstream
:
std::stringstream stream;
stream <<AppVersions.wVersion;
wVersion = stream.str();
std::stringstream;
stream@Petesh我正在尝试您的解决方案,并收到此错误错误1错误C2668:'std::to_string':对重载函数的调用不明确…
有什么线索可以修复它吗?谢谢我正在尝试您的解决方案,并得到此错误error 1 error C2668:'std::to_string':对重载函数的调用不明确…
有什么线索可以修复它吗?谢谢它在我的Visual Studio 2013上编译得非常完美,但我想您可以添加显式强制转换,例如到_string((unsigned short)myWord))
此外,请确保包含标题,例如#include
是否使用Visual Studio 2010?@Dimi您可以尝试强制转换为到_string
直接支持的类型,我想试试int
。