C++ TCHAR 和 WCHAR 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4205809/
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-28 14:49:59  来源:igfitidea点击:

What is difference between TCHAR and WCHAR?

c++winapi

提问by Mihran Hovsepyan

I've opened winnt.h header file and found there this two lines:

我打开了 winnt.h 头文件,发现有这两行:

typedef wchar_t WCHAR;

and

typedef WCHAR TCHAR, *PTCHAR;

but there was comment in one of my poststhat there is some difference between them. Then what is the difference?

但是在我的一篇帖子中有评论说它们之间存在一些差异。那么有什么区别呢?

回答by bmargulies

If you read the entire header, you will find:

如果您阅读整个标题,您会发现:

#ifdef _UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif

or words to that effect.

或大意的词。

Perhaps MS has removed the narrow option of late.

也许 MS 已经删除了最近的窄选项。

回答by Wyatt Anderson

TCHARcan be either charor WCHARbased on the platform. WCHARis always a 16-bit Unicode character, wchar_t.

TCHAR可以是charWCHAR基于平台。WCHAR始终是 16 位 Unicode 字符,wchar_t.

回答by Sagar

http://msdn.microsoft.com/en-us/library/aa383751%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/aa383751%28VS.85%29.aspx

TCHAR:

查尔:

A WCHAR if UNICODE is defined, a CHAR otherwise.

如果定义了 UNICODE,则为 WCHAR,否则为 CHAR。

WCHAR:

WCHAR:

A 16-bit Unicode character. For more information, see Character Sets Used By Fonts.

一个 16 位 Unicode 字符。有关更多信息,请参阅字体使用的字符集。

回答by Mohit Dabas

Technically speaking there is no difference because you cannot typedef two different entities to a single one. Let us See An Example...

从技术上讲,没有区别,因为您不能将两个不同的实体定义为一个。让我们看一个例子...

typedef char a;
typedef char  b;
typedef a b, c;

This Definition Works But If a Change The Above Definition To This

此定义有效,但如果将上述定义更改为此

typedef char a;
typedef char * b;
typedef a b, c;

Error 1 error C2040: 'b' : 'a' differs in levels of indirection from 'char *'

错误 1 ​​错误 C2040:“b”:“a”与“char *”的间接级别不同

Another One

另一个

typedef char a;
typedef int b;
typedef a b, c;

Error 1 error C2371: 'b' : redefinition; different basic types

错误 1 ​​错误 C2371:'b':重新定义;不同的基本类型

So By Analyzing These Things Only Same Type Can Defined Together.

所以通过分析这些东西,只有相同的类型才能定义在一起。