C++ – How to construct a std::string from a DWORD


I have following code:

Tools::Logger.Log(string(GetLastError()), Error);

GetLastError() returns a DWORD a numeric value, but the constructor of std::string doesn't accept a DWORD.

What can I do?

Best Solution

You want to read up on ostringstream:

#include <sstream>
#include <string>

int main()
   std::ostringstream stream;
   int i = 5;
   stream << i;
   std::string str = stream.str();