First introduce the next wchar_t type
First, the origin of the wchar_t type
We know that a char type variable can store a byte character, it can be used to save English characters and punctuation, but not for characters such as kanji, Korean, and Japanese, because Chinese, Korean, and Japanese each have two bytes, in order to solve this problem, C + + puts forward WCHAR The _t type, called a double-byte type, is also known as a wide character type.
Second, the following is an example
int main (int argc, wchar_t* argv[]) {//Use the setlocale function to set the native language to Chinese Simplified setlocale (lc_all, "CHS"),//lc_all to set all options (including financial currency, decimal point, Time date format, language string usage habits, etc.), CHS Express Chinese Simplified wchar_t wt[] = L "Hello China!" ";//capital Letter L tells the compiler to allocate two bytes of space for" medium "wcout<<wt<<endl;//use wcout instead of cout output wide character, Wcin class instead of CIN input wide character cout<< wcslen (WT) <<endl;//wcslen the length of the output wide string, the output length is 5cout<<sizeof (WT) <<endl;//the output length is 12 bytes, the last wchar_t type of ' \ 0 ' two bytes return 0;}
Conversion between three, and string types
String str ("Hello China"); wchar_t * WC = new Wchar_t[str.size ()];swprintf (wc,100,l "%s", Str.c_str ()); Note the uppercase//WC points to the memory area to store this wchar_t type of "Hello China".
Introduction to C + + wchar_t and conversion to string type