I am working on very old C++ project. When building my C++ code in Visual Studio 6 I am getting error "cannot convert from 'unsigned short [9]' to 'char []'".
for code below:
char variable[] = _T("something");
I googled and tried to understand the issue. It could be the way I am building it.
I've already tried the step written in https://mihai-nita.net/2006/07/23/visual-studio-unicode-projects/ (adding UNICODE & _UNICODE in preprocessor). It would be very helpful if someone can suggest a solution to correct this error.
The
_Tmacro expands to either a narrow or wide string literal depending on the state of theUNICODEmacro. IfUNICODEisn't defined_Twill expand to acharstring, and ifUNICODEis defined_Twill expand to a wide char string.If you're using
_T, you should use the typeTCHAR, which will similarly expand to eithercharorwchar_tdepending on the state of theUNICODEmacros:This will expand to
if
UNICODEis not defined, and will expand to something likeif
UNICODEis defined.It's worth noting that
wchar_twasn't a real type in early versions of Visual C++, but rather just atypedeffor (or macro expanding to)unsigned short, which is why the error message you're seeing references that instead ofwchar_t.