What does _T stands for in a CString

独自空忆成欢 提交于 2019-11-26 20:48:14

问题


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


回答1:


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




回答2:


From MSDN:

Use the _T macro to code literal strings generically, so they compile as Unicode strings under Unicode or as ANSI strings (including MBCS) without Unicode




回答3:


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.




回答4:


It stands for TEXT. You can peek the definition when using IDE tools:

#define _TEXT(x)    __T(x)

But I would like to memorize it as "Transformable", or "swi-T-ch":

L"Hello"  //change "Hello" string into UNICODE mode, in any case;

_T("Hello") //if defined UNICODE, change "Hello" into UNICODE; otherwise, keep it in ANSI.


来源:https://stackoverflow.com/questions/15498070/what-does-t-stands-for-in-a-cstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!