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

有帮助吗?

解决方案

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

其他提示

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); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top