ANSI vs UNICODE

博客介绍了C RunTime Library环境下,Unicode在ANSI C中的定义,列举了标准ANSI C字符串函数及等价Unicode函数,指出调用Unicode函数可将ANSI字符串函数前缀str替换为wcs。还说明了创建ANSI/Unicode通用代码的方法,以及宽字符输入输出流相关内容。

环境:C RunTime Library

Unicode 在ANSI C中的定义:
String.h

typedef
unsigned short wchar_t

标准的ANSI C字符串函数及等价Unicode函数
char * strchr(const char *, int);
wchar_t * wcschr(const wchar *, wchar_t);

int strcmp(const char *, const char *);
int wcscmp(const wchar_t *, const wchar_t *);

char * strcpy(char *, const char *);
wchar_t * wcscpy(wchar_t *, const wchar_t *);

size_t strlen(const char *);
size_t wcslen(const wchar_t *);
所有的Unicode函数均以wcs开头,wcs是宽字符串的英文缩写。若要调用Unicode函数,只要用前缀wcs来取代ANSI字符串函数的前缀str即可。

创建ANSI/Unicode通用代码必须包含TChar.h文件而不是String.h文件。它包含了一组宏用以避免直接调用str函数或wcs函数。由是否定义_UNICODE控制选择。拥有字符串参数的所有C运行期函数都在TChar.h文件中定义了一个通用宏。使用TCHAR与_TEXT宏,定义字符串数组。

char *szTesst = “This is a ANSI string!”
wchar_t *szTest = L“This is a Unicode string!”;
TCHAR *szTest = _TEXT“This is a ANSI/Unicode string!”;

wistream  wcin    Reads wide-character input from the standard input channel
wostream wcout Writes "normal" wide-character output to the standard output channel
wostream wcerr Writes wide-character error messages to the standard error channel
wostream wclog Writes wide-character log messages to the standard logging channel

[参考文献]
Jeffrey Richter -- Programming Applications for Microsoft Windows, Fourth Edition
Nicolai M. Josuttis -- C++ Standard Library, The: A Tutorial and Reference

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值