如何在Visual C ++中将WORD类型转换为字符串

时间:2015-10-08 12:43:04

标签: c++ visual-c++

有人可以解释如何在C ++中将WORD转换为字符串吗?

  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); 

1 个答案:

答案 0 :(得分:1)

Visual C ++上下文中的WORDunsigned 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>