How do I construct a std::string from a DWORD?

前端 未结 8 2277
死守一世寂寞
死守一世寂寞 2020-12-07 00:30

I have following code:

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

GetLastError() returns a DWORD a numeric

8条回答
  •  情书的邮戳
    2020-12-07 01:24

    Since C++11

    std::to_string() with overloads for int, long, long long, unsigned int, unsigned long, unsigned long long, float, double, and long double.

    auto i = 1337;
    auto si = std::to_string(i); // "1337"
    auto f = .1234f;
    auto sf = std::to_string(f); // "0.123400"
    

    Yes, I'm a fan of auto.

    To use your example:

    Tools::Logger.Log(std::to_string(GetLastError()), Error);
    

提交回复
热议问题