wcout输出时显示不了中文 || 如何使用wprintf和wcout输出汉字

wcout输出时显示不了中文

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"

http://www.cnblogs.com/fangyukuan/archive/2010/08/19/1804055.html

http://fangyukuan.blog.163.com/blog/static/193336952010719114744326/







  如何使用wprintf和wcout输出汉字  2011-03-25 11:36:56

分类: C/C++

在非Unicode下,输出汉字直接使用printf即可。如下:

      char *SName = "生物医学工程";
      printf("printf: %s\n", SName);

      尝试了一下在Unicode下(VS2008),使用wprintf和wcout输出汉字,没有成功,百度了一下,发现如下解释:

      由于在控制台下,系统默认的locale汉字集为GB码(指装有中文系统),在使用Unicode时,是系统帮忙将宽字符转换为多字节字符,因此在控制台程序中直接显示Unicode的汉字时,需要进行设置。

      上面的解释看的也是半懂不懂的,但是设置方法是很固定的,就是通过locale头文件中的setlocale函数。比如输出“生物医学工程”这几个汉字,方法如下:

#include "stdafx.h"
#include <locale>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *Name = L"生物医学工程";
setlocale(LC_ALL, "chs");
while (*Name != '\0')
   wcout<<*Name++;
wcout<<endl;
Name -= 6;

//while (*Name != '\0')
_tprintf(L"wprintf: %s\n", Name);

return 0;
}


你可能感兴趣的:(JavaScript,js)