I try to print UTF-8 string to windows console. The code page of console is set to 65001 (utf-8), the font is set to lucida console and the c++ source file encoding is utf-8 without bom. Consider the following code:
#include<iostream>
#include<locale>
#include<clocale>
int main(int narg, char** arg){
using namespace std;
cout<<"C++ locale: "<<cout.getloc().name()
<<"\nC locale: "<<setlocale(LC_ALL, 0)<<"\n";
cout<<"中文\n";
printf("中文\n");
return 0;
}
The output is:
C++ locale: C
C locale: C
������
中文
Could anybody explain it and give a solution (Make c++ and c have the same correct output.)? Thanks very much.
System: win7(32 bit)
Compiler: vs2012 express
Edit: The program is correct with gcc under ubuntu12.