char *和wchar_t *之间的区别 [英] Difference between char* and wchar_t*

查看:316
本文介绍了char *和wchar_t *之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MFC的新手。我正在尝试做简单的mfc应用程序,但在某些地方我感到困惑。例如, SetWindowText 有两个api, SetWindowTextA SetWindowTextW 一个api接受 char * ,另一个api接受 wchar_t *

I am new to MFC. I am trying to do simple mfc application and I'm getting confuse in some places. For example, SetWindowText have two api, SetWindowTextA, SetWindowTextW one api takes char * and another one accepts wchar_t *.

char * wchar_t * 的用途是什么?

推荐答案

char 用于所谓的ANSI函数系列(通常,函数名称以结尾A ),或更通常称为使用ASCII字符集。

char is used for so called ANSI family of functions (typically function name ends with A), or more commonly known as using ASCII character set.

wchar_t 是用于新的所谓的Unicode(或Wide)函数系列(通常,函数名称以 W 结尾),该函数使用UTF-16字符集。它与UCS-2非常相似,但不完全相同。如果字符需要2个以上的字节,它将被转换为2个复合代码点,这可能会非常令人困惑。

wchar_t is used for new so called Unicode (or Wide) family of functions (typically function name ends with W), which use UTF-16 character set. It is very similar to UCS-2, but not quite it. If character requires more than 2 bytes, it will be converted into 2 composite codepoints, and this can be very confusing.

如果要将一个转换为另一个,则为不是很简单的任务。您将需要使用类似 MultiByteToWideChar ,它需要知道并提供输入ANSI字符串的代码页。

If you want to convert one to another, it is not really simple task. You will need to use something like MultiByteToWideChar, which requires knowing and providing code page for input ANSI string.

这篇关于char *和wchar_t *之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆