C++ TEXT macro of TCHAR*

1.7k Views Asked by At

I am trying to create a TCHAR* variable by using

TCHAR* example = TEXT("example");

but it wont even compile and says: A value of type const wchar_t* cannot be used to initialize an entity of type TCHAR*. What should I do?

1

There are 1 best solutions below

2
Carlos A. Ibarra On BEST ANSWER

You have to add const, because the TEXT() macro returns a pointer to a const wchar_t.

const TCHAR* example = TEXT("example");

If the assignment were allowed without the const, you would be able to modify the const wchar_t data through the pointer.

See also A value of type "const char*" cannot be used to initialize an entity of type "char *"