Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

c++ - How do I 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...