ANSI vs Unicode

xiaoxiao2021-03-06  67

Environment: C Runtime Library

Definition in ANSI C in ANSI C: String.htypedEf Unsigned Short Wchar_t

Standard ANSI C String Functions and Equivalent Unicode Functions 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; size_t wcslen (const wchar_t *); all Unicode functions start with WCS, WCS is a wide string English abbreviation. To call the Unicode function, just use the prefix WCS to replace the prefix STR of the ANSI string function.

Creating an ANSI / Unicode generic code must contain tchar.h files instead of string.h files. It contains a set of macros to avoid calling STR functions or WCS functions directly. Whether or not to define the _unicode control selection. All C run functions with string parameters are defined in tchar.h files. Use TCHAR with the _Text macro to define the array of strings.

Char * sztest = "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 channelwostream wcout Writes "normal" wide-character output to the standard output channelwostream wcerr Writes wide-character error messages to the standard error channelwostream wclog Writes wide-character log messages to the standard logging channel

[Reference] Jeffrey Richter - Programming Applications for Microsoft Windows, Fourth Editionnicolai M. Josuttis - C Standard Library, The: a Tutorial and Reference

转载请注明原文地址:https://www.9cbs.com/read-120083.html

New Post(0)