As we know, C uses a char data type to represent a 8-bit ANSI character, and by default when a string is declared in the code, the C compiler converts the characters in the string into an array of 8-bit char data types:
Copy Code code as follows:
An 8-bit character
char c = ' A ';
An array of 8-bit character and 8-bit terminating zero
Char szbuffer[100] = "A String";
Microsoft's C + + compiler defines a built-in data type wchar_t, which represents a 16-bit Unicode (UTF-16) character. This parameter type is defined only when the compiler specifies the/zc:wchar_t compiler switch.
The methods for declaring Unicode characters and strings are as follows:
Copy Code code as follows:
A 16-bit Character
wchar_t c= L ' A ';
An array up to 16-bit characters and a 16-bit terminating zero
wchar_t szbuffer[100] = L "A String";
Uppercase letters before strings L 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 enable it to compile. WinNT.h defines the following types and macros:
Copy Code code as follows:
#ifdef UNICODE
typedef WCHAR TCHAR, *ptchar, ptstr;
typedef CONST WCHAR *pctstr;
#define __text (quote) l# #quote
#else
typedef CHAR TCHAR, *ptchar, ptstr;
typedef CONST CHAR *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:
Copy Code code 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[100] = TEXT ("A String");
The above mentioned is all Neri of this article, hope everybody can like.