如何在visualc++中将WORD类型转换为字符串
How to convert WORD type to string in Visual C++
谁能解释一下如何将WORD转换为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
是unsigned short
的类型定义。
所以你可以使用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();
确保包含<sstream>
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何将字符串类型转换为 ostringstream
- 如何将两个 jlong 数据类型转换为 jstring,然后将两个字符串连接在一起以便从 JNI 将字符串返回给 jav
- 将函数指针类型转换为相应的字符串
- 将任何类型的类型转换为字符串 c++
- 如何将模板类型转换为字符串(如果它也可以是字符串)
- 字符串常量之前的预期构造函数、析构函数或类型转换
- C++大小写中的类型转换常量字符串
- 使用java jni时转换字符串类型
- 字符串的类型转换
- 字符串流与C++中的类型转换
- 如何在visualc++中将WORD类型转换为字符串
- 为什么在运行时将字符串类型转换为DWORD时会得到不同的值?
- QVariant中的自定义类型转换为空字符串
- std::字符串的类型转换
- C++ 隐式类型转换字符串 -> int?
- (字符串)字符类型转换
- 如何在VS2012中转换自定义类型为字符串
- 你认为是什么让这个C++代码变慢了?(它循环通过ADODB记录集,将COM类型转换为字符串,并填充ostringstre