Anon
Anon

Reputation: 1354

conversion between UINT and LPCWSTR in c++

How can I get the string representation (as LPCWSTR) of a variable of type UINT?

Upvotes: 0

Views: 4495

Answers (2)

Robin Caron
Robin Caron

Reputation: 627

Try _itow. It takes an unsigned integer, the address of a wide character buffer and what base to use for the conversion.

Here's an example:

UINT x = 1000245; 
LPWSTR y = (LPWSTR)malloc(30); 

_itow(x, y, 10); 

Upvotes: 1

Marlon
Marlon

Reputation: 20312

A LPCWSTR is a constant LPWSTR, which is a pointer to a wide-character string. You should use a std::wstringstream:

#include <sstream>

// ...

UINT number = 42;
std::wstringstream wss;
std::wstring str;

wss << number;
wss >> str;
LPCWSTR result = str.c_str();

Upvotes: 4

Related Questions