Character and string processing-ANSI and Unicode characters,-ansiunicode
We know that the C language uses the char data type to represent an eight-digit ANSI character. By default, when a string is declared in the code, the C compiler converts the characters in a string to an array consisting of eight-bit char data types:
// An 8-bit characterchar c = 'A';// An array of 99 8-bit character and 8-bit terminating zerochar szBuffer[100] = "A String";
Microsoft's C/C ++ compiler defines a built-in data type wchar_t that represents a 16-bit Unicode (UTF-16) character. This parameter type is defined only when the/Zc: wchar_t compiler switch is specified by the compiler.
The methods for declaring Unicode characters and strings are as follows:
// A 16-bit characterwchar_t c= L'A';// An array up to 99 16-bit characters and a 16-bit terminating zerowchar_t szBuffer[100] = L"A String";
The uppercase letter L before the string notifies the compiler that the string should be compiled into a Unicode string.
In addition, you can use ANSI or Unicode characters/strings to compile the code. WinNT. h defines the following types and macros:
#ifdef UNICODEtypedef WCHAR TCHAR, *PTCHAR, PTSTR;typedef CONST WCHAR *PCTSTR;#define __TEXT(quote) L##quote#elsetypedef CHAR TCHAR, *PTCHAR, PTSTR;typedef CONST CHAR *PCTSTR;#define __TEXT(quote) quote#endif#define TEXT(quote) __TEXT(quote)
Use these types and macros to write code. Both ANSI and Unicode characters can be compiled as follows:
// If UNICODE define, a 16-bit character; else an 8-bit characterTCHAR c = TEXT('A');// If UNICODE define, an array of 16-bit character; else 8-bit characterTCHAR szBuffer[100] = TEXT("A String");