I inherited some old code which needs to stay multibyte/unicode compatible. It currently uses the _T() macro for this. I was wondering if std::strings are introduced, is _T() still needed?
e.g
std::string foo(_T("hello"));
Or is it now redundant?
It's not only unneeded. It's wrong. The _T macro expands to convert the string literal to a wide character (wchar_t) string literal if UNICODE is defined. However, the std::string constructor never expects a wide character string (const wchar_t*). It always expects const char*.
What you might do, if you were still concerned about this sort of thing (compiling for both Unicode and ANSI versions of the WinAPI), is define a new type based on std::basic_string
typedef std::basic_string<TCHAR> tstring;
And then this would be correct:
tstring foo(_T("hello"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With