Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does _T stands for in a CString

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

like image 332
CodeRider Avatar asked Mar 19 '13 11:03

CodeRider


People also ask

What is CString data type?

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.

What does l mean in C++?

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.

How do you use CString?

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 .

Where is Tchar defined?

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).


2 Answers

_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.

like image 81
MvG Avatar answered Sep 25 '22 11:09

MvG


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.

like image 43
john Avatar answered Sep 22 '22 11:09

john