Skip to content

关于VC中的TCHAR和char

2010 六月 1
tags: , ,
by 荒野无灯

TCHAR is defined as wchar_t in a Unicode build, but as char in a non Unicode build. So if you’re not using Unicode (i.e. don’t have _UNICODE defined in the project’s preprocessor settings), then you can simply pass in the TCHAR str[256] to a function that expects a char * , otherwise you will have to convert the string from Unicode to non-Unicode using wcstombs function.

当你编译UNICODE 版本的程序时,TCHAR 被定义为wchar_t (宽字符),在非unicode编译版本中它就相当于ansi C中的char .
因此,如果你没有使用Unicode(比如你没有在项目的预处理设置里面定义_UNICODE ),那么你可以简单地将 TCHAR str[256] 传递给一个需要char * 类型参数的函数,否则你不得不用wcstombs (荒野无灯注:这个函数已经不推荐使用了,推荐使用wcstombs_s)函数将这个字符串从Unicode转换为非unicode字符串。

from: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/0073fa7b-5cf5-469c-978f-2961f9d4ecb2/

喜欢这篇文章吗?

请订阅本站 RSS feed填写您的邮件地址,订阅我们的精彩内容:,欢迎点击这里捐赠以支持荒野无灯转播到腾讯微博 转播到腾讯微博

作者:荒野无灯
出处:Hacklog【Hacklog】

声明: 本站遵循 署名-非商业性使用-相同方式共享 3.0 共享协议. 转载请注明转自Hacklog【荒野无灯weblog】

本文链接: http://ihacklog.com/?p=3863

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <q cite=""> <strong>

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS