C++ _T 在 CString 中代表什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15498070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:26:07  来源:igfitidea点击:

What does _T stands for in a CString

c++unicodecstring

提问by CodeRider

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

“T”在字符串中代表什么。例如 _T("Hello")。我在需要 unicode 支持的项目中看到过这个。它实际上告诉处理器什么

回答by MvG

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

_T代表“文本”。当且仅当您使用 Unicode 支持编译源代码时,它才会将您的文字转换为 Unicode 宽字符文字。请参阅http://msdn.microsoft.com/en-us/library/c426s321.aspx

回答by Tony The Lion

From MSDN:

来自 MSDN:

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

使用_T宏对文字字符串进行一般编码,因此它们可以编译为 Unicode 下的 Unicode 字符串或不使用 Unicode 的 ANSI 字符串(包括 MBCS)

回答by john

It's actually used for projects where Unicode andANSI 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.

它实际上用于需要 UnicodeANSI 支持的项目。它告诉编译器根据预编译器定义的值将字符串文字编译为 Unicode 或 ANSI。

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.

你为什么要这样做是另一回事。如果您想单独支持 Unicode,那么只需编写 Unicode,在本例中为L"Hello". _T()当您需要支持 Windows NT 及更高版本(支持 Unicode)和 Windows 9x/ME(不支持)时,添加了该宏。如今,使用这些宏的任何代码都已过时,因为所有现代 Windows 版本都是基于 Unicode 的。

回答by JC Ju

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

它代表文本。使用IDE工具时可以查看定义:

#define _TEXT(x)    __T(x)

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

但我想记住它为“可变形”或“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.