首页 > 代码库 > c++之cout、wcout、printf、wprintf不显示汉字或者遇到汉字即中断显示的原因

c++之cout、wcout、printf、wprintf不显示汉字或者遇到汉字即中断显示的原因

原因:机器本地性引起,cout输出的时候,其并不知道你输出的字符编码是代表的什么语言,所以会根据你计算机的区域设置而确定,但我的计算机设置的是英文的,所以将字符编码按照英文进行处理,很明显也就很快显示不出来了,因为cout发现这根本不是英文,不知道是什么玩意。

如果你的计算机本来就设置的中文区域,就不会出现这样的问题。

关键是wcout为何也不能输出中文呢,其处理的不是utf-16吗?这难道还要分计算机区域设置,不是全球化编码吗?原因很简单,utf-16有代理页一说,还是和你计算机相关


wcout输出时显示不了中文,加上下面这句就行了。

std::wcout.imbue(std::locale("chs"));


Primary language

Sublanguage

Language string

Chinese

Chinese

"chinese"

Chinese

Chinese (simplified)

"chinese-simplified" or "chs"

Chinese

Chinese (traditional)

"chinese-traditional" or "cht"

Czech

Czech

"csy" or "czech"

Danish

Danish

"dan" or "danish"

Dutch

Dutch (default)

"dutch" or "nld"

Dutch

Dutch (Belgium)

"belgian", "dutch-belgian", or "nlb"

English

English (default)

"english"

English

English (Australia)

"australian", "ena", or "english-aus"

English

English (Canada)

"canadian", "enc", or "english-can"

English

English (New Zealand)

"english-nz" or "enz"

English

English (United Kingdom)

"eng", "english-uk", or "uk"

English

English (United States)

"american", "american english", "american-english", "english-american", "english-us", "english-usa", "enu", "us", or "usa"

Finnish

Finnish

"fin" or "finnish"

French

French (default)

"fra" or "french"

French

French (Belgium)

"frb" or "french-belgian"

French

French (Canada)

"frc" or "french-canadian"

French

French (Switzerland)

"french-swiss" or "frs"

German

German (default)

"deu" or "german"

German

German (Austria)

"dea" or "german-austrian"

German

German (Switzerland)

"des", "german-swiss", or "swiss"

Greek

Greek

"ell" or "greek"

Hungarian

Hungarian

"hun" or "hungarian"

Icelandic

Icelandic

"icelandic" or "isl"

Italian

Italian (default)

"ita" or "italian"

Italian

Italian (Switzerland)

"italian-swiss" or "its"

Japanese

Japanese

"japanese" or "jpn"

Korean

Korean

"kor" or "korean"

Norwegian

Norwegian (default)

"norwegian"

Norwegian

Norwegian (Bokmal)

"nor" or "norwegian-bokmal"

Norwegian

Norwegian (Nynorsk)

"non" or "norwegian-nynorsk"

Polish

Polish

"plk" or "polish"

Portuguese

Portuguese (default)

"portuguese" or "ptg"

Portuguese

Portuguese (Brazil)

"portuguese-brazilian" or "ptb"

Russian

Russian (default)

"rus" or "russian"

Slovak

Slovak

"sky" or "slovak"

Spanish

Spanish (default)

"esp" or "spanish"

Spanish

Spanish (Mexico)

"esm" or "spanish-mexican"

Spanish

Spanish (Modern)

"esn" or "spanish-modern"

Swedish

Swedish

"sve" or "swedish"

Turkish

Turkish

"trk" or "turkish"


c++之cout、wcout、printf、wprintf不显示汉字或者遇到汉字即中断显示的原因