问题
I need to make and WCHAR. But it wont work, and i always get an error:
Error C2440 'initializing': cannot convert from 'const wchar_t [11]' to 'WCHAR *'
StateError (active) E0144 a value of type "const wchar_t *" cannot be used to initialize an entity of type "WCHAR *
My code:
WCHAR *Testlooll = L"TEST";
回答1:
L"TEST"
is a string literal of type const wchar_t[5]
, which is an array of const characters (since the literal exists in read-only memory). You are trying to initialize a WCHAR*
, which is a pointer to a non-const character, to point at that array.
Initializing a pointer to non-const character data to point at an array of const character data is deprecated in C++98 (to maintain backwards compatibility with legacy code), and is illegal in C++11 onwards.
You need to change the declaration of Testlooll
according:
const WCHAR *Testlooll = L"TEST";
Or:
LPCWSTR Testlooll = L"TEST";
来源:https://stackoverflow.com/questions/52137990/i-cannot-initializate-wchar