ANSI vs UNICODE

来源:互联网 发布:java系统业务日志设计 编辑:程序博客网 时间:2024/04/30 13:57

环境: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

原创粉丝点击