Unicode is often introduced in programming books, and various formats are often used in string functions. The following uses "ABC me and you" as an example to describe Unicode.
Test source code:
Tchar * P = _ T ("ABC me you him ");
STD: cout <_ tcsclen (P );
We wroteCodeIt should look like this, that is, code that conforms to both ANSI and Unicode, using the _ t macro and _ TS function set.
I. ANSI encoding: one common English letter, two bytes of Chinese characters. "ABC me you" occupies 9 bytes.
There are no related options in the compilation options.
Output 9
In this case, _ tcsclen is strlen and the result is the number of bytes.
Use the multi-character function, that is, the multibyte function. Set _ MBCS in the compilation options, the default project generated by this option VC contains (Project-> setting-> C ++-> Preprocessor setting ).
In this case, _ tcsclen is _ mbslen. The output value is 6, which actually occupies 9 bytes.
2. Unicode encoding. The so-called wide characters, English characters and Chinese characters both occupy 2 bytes. In the compilation options, SET _ Unicode and Unicode.
Source code is equivalent to wchar_t * P = l "ABC me you him ";
STD: cout <wcslen (P );
The result is 6, which actually occupies 12 bytes .;