关于VC中的TCHAR和char

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填写您的邮件地址,订阅我们的精彩内容:

相关日志

回复 (0)

› 尚无评论。

发表评论 修改评论取消编辑

允许使用的标签 - 您可以在评论中使用如下的 HTML 标签以及属性。

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

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

引用通告 (0)

› 尚无引用通告。

开灯