3

Could anyone explain how to convert WORD to string in C++, please?

  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); 
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • http://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c – Anya Shenanigans Oct 08 '15 at 12:46
  • @Petesh I am trying your solution and getting this error `Error 1 error C2668: 'std::to_string' : ambiguous call to overloaded functio...` Any clue how to fix it? Thanks! – NoWar Oct 08 '15 at 12:53

1 Answers1

2

a WORD in Visual C++ context is a type-definition for unsigned short.

so you can use std::to_string for this task:

 wVersion = std::to_string(AppVersions.wVersion); 

Edit: appearently Visual Studio 2010 doesn't support C++11 features completly, use std::stringstream instead:

std::stringstream stream;
stream <<AppVersions.wVersion;
wVersion  = stream.str();

make sure to include <sstream>

David Haim
  • 25,446
  • 3
  • 44
  • 78