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