Rajasekhar
Rajasekhar

Reputation: 894

How to convert DWORD to wstring?

I want to convert a DWORD value to wstring value.

DWORD dw;
wstring wstr(L"");
dw = 2;

Can you suggest ideal way to assign 'dw' to 'dwstr' ?

Upvotes: 2

Views: 11740

Answers (3)

Jonas Byström
Jonas Byström

Reputation: 26169

On C++03 you can do:

std::wstringstream stream;
stream << dw;
wstr = stream.str();

Upvotes: 0

Jerry Coffin
Jerry Coffin

Reputation: 490178

If you're using an older compiler that doesn't have std::to_wstring, consider lexical_cast (e.g., from Boost) instead.

As an aside, if you want to create wstr as an empty string, just wstring wstr; suffices.

Upvotes: 2

Qaz
Qaz

Reputation: 61920

Use std::to_wstring:

std::wstring wstr = std::to_wstring(dw);

Upvotes: 13

Related Questions