What does the "T" represents in a string. For example _T("Hello").I have seen this in projects where unicode support is needed.What it actually tells the processor
A CString object supports either the char type or the wchar_t type, depending on whether the MBCS symbol or the UNICODE symbol is defined at compile time. A CString object keeps character data in a CStringData object.
L is the prefix for wide character literals and wide-character string literals which tells the compiler that the char or string is of type wide-char.
To use a CString object as a C-style string, cast the object to LPCTSTR . In the following example, the CString returns a pointer to a read-only C-style null-terminated string. The strcpy function puts a copy of the C-style string in the variable myString .
TCHAR is simply a macro that expands to char in ANSI builds (i.e. _UNICODE is not defined) and wchar_t in Unicode builds ( _UNICODE is defined). There are various string types based on the TCHAR macro, such as LPCTSTR (long pointer to a constant TCHAR string).
_T
stands for “text”. It will turn your literal into a Unicode wide character literal if and only if you are compiling your sources with Unicode support. See http://msdn.microsoft.com/en-us/library/c426s321.aspx.
It's actually used for projects where Unicode and ANSI support is required. It tells the compiler to compile the string literal as either Unicode or ANSI depending on the value of a precompiler define.
Why you would want to do this is another matter. If you want to support Unicode by itself then just write Unicode, in this case L"Hello"
. The _T()
macro was added when you needed to support Windows NT and later (which support Unicode) and Windows 9x/ME (which do not). These days any code using these macros is obsolete, since all modern Windows versions are Unicode-based.
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