问题描述
例如:
// This will become either SomeMethodA or SomeMethodW,
// depending on whether _UNICODE is defined.
SomeMethod( _T( "My String Literal" ) );
// Becomes either AnotherMethodA or AnotherMethodW.
AnotherMethod( _TEXT( "My Text" ) );
我看过两者。 _T似乎是为了简洁和_TEXT为了清楚。这只是一个主观的程序员偏好还是更技术性的?例如,如果我使用一个在另一个,我的代码不会编译一个特定的系统或一些旧版本的头文件?
I've seen both. _T seems to be for brevity and _TEXT for clarity. Is this merely a subjective programmer preference or is it more technical than that? For instance, if I use one over the other, will my code not compile against a particular system or some older version of a header file?
推荐答案
SDK的一个简单grep向我们展示,答案是没有关系 - 它们是相同的。它们都变成 __ T(x)
。
A simple grep of the SDK shows us that the answer is that it doesn't matter—they are the same. They both turn into __T(x)
.
C:\...\Visual Studio 8\VC>findstr /spin /c:"#define _T(" *.h
crt\src\tchar.h:2439:#define _T(x) __T(x)
include\tchar.h:2390:#define _T(x) __T(x)
C:\...\Visual Studio 8\VC>findstr /spin /c:"#define _TEXT(" *.h
crt\src\tchar.h:2440:#define _TEXT(x) __T(x)
include\tchar.h:2391:#define _TEXT(x) __T(x)
并且为了完整性:
C:\...\Visual Studio 8\VC>findstr /spin /c:"#define __T(" *.h
crt\src\tchar.h:210:#define __T(x) L ## x
crt\src\tchar.h:889:#define __T(x) x
include\tchar.h:210:#define __T(x) L ## x
include\tchar.h:858:#define __T(x) x
但是,对于C ++,您应该使用 TEXT()
而不是 _TEXT() / code>,但它(最终)也扩展到同样的东西。
However, technically, for C++ you should be using
TEXT()
instead of _TEXT()
, but it (eventually) expands to the same thing too.
这篇关于我应该使用_T还是_TEXT C ++字符串文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!