In the previous article:
If the ASCII code is directly converted:
Result = (ENV)-> newstringutf (STR );
If it contains Chinese characters:
Int length = mbstowcs (wchar_t * wcstr, const char * mbstr, size_t count );
The third parameter count of this function must be twice the length of mbstr,Otherwise, Chinese characters are garbled.
.
To use mbstowcs, you must set locale correctly. Simply write setlocale (lc_all, ""); can the current language environment support all encoding characters?
General locale "zh_CN.UTF-8" in Linux"
UTF-8 is encoding, en_US.UTF-8, zh_CN.UTF-8 is called character set, that is to say, 'A', 'B', 'medium', 'country 'and other corresponding integer, en_us and zh_cn is also the language environment
The number of characters contained in the en_US.UTF-8 and zh_CN.UTF-8 is basically the same, about 70 thousand Chinese characters, encoding is UTF-8 encoding, character set is
Unicode, the character sets of zh_cn.gb18030 and zh_cn.gbk are both Unicode 3
Is equivalent
The difference in the language environment is another thing. Chinese and foreign people express time, numbers, and habits are different, so they must be separated.
Most programs choose whether the language of the interface is Chinese or English based on the language environment variables.
Below are some outputs on the console >>>>>
View the installed language packs:
# Locale-
View the current settings:
# Locale
Modify settings:
# Export lc_all = ZH_CN.UTF-8