Question

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

Was it helpful?

Solution

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

OTHER TIPS

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); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top