We know that the C language uses the char data type to represent a 8-bit ANSI character, and by default when a string is declared in code, the C compiler converts the characters in the string into an array of 8-bit char data types:
// An 8-bit character Char ' A ' ; // An array of 8-bit character and 8-bit terminating zero Char szbuffer["A String";
Microsoft's C + + compiler defines a built-in data type, wchar_t, that represents a 16-bit Unicode (UTF-16) character. The compiler defines this parameter type only if the/zc:wchar_t compiler switch is specified.
The methods for declaring Unicode characters and strings are as follows:
// a 16-bit characterwchar_t c= L'a'; // An array up to 16-bit characters and a 16-bit terminating zerowchar_t szbuffer[[] = L"
a String
";
The uppercase letter L before the string notifies the compiler that the string should compile a Unicode string.
In addition, when writing code, you can use ANSI or Unicode characters/strings to make it compile. WinNT.h defines the following types and macros:
**pctstr; #define __text (quote) l# #quote#else**pctstr; #define __text (quote) quote#endif#define TEXT (quote) __text (quote)
Using these types and macros to write code, whether using ANSI or Unicode characters, can be compiled as follows:
// If UNICODE Define, a 16-bit character; else an 8-bit character TCHAR C = TEXT ('A'); // If UNICODE Define, an array of 16-bit character; else 8-bit character TCHAR szbuffer[] = TEXT ("A String");
Character and string handling-ansi characters and Unicode characters