相同的语言环境,不同的输出
same locale, different output
我尝试将UTF-8字符串打印到windows控制台。控制台代码页设置为65001 (utf-8),字体设置为lucida console, c++源文件编码为utf-8。考虑下面的代码:
#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;
}
输出为:
C++ locale: C
C locale: C
������
中文
谁能解释一下并给出一个解决方案(使c++和c有相同的正确输出)?非常感谢。
System: win7(32位)
编译器:vs2012 express编辑:gcc在ubuntu12下的程序是正确的。
控制台默认不显示UTF,但是您可以使用:
chcp 65001
将控制台更改为UTF或使用SetConsoleOutputCP
通过代码更改它
希望这些有帮助:)附录:抱歉,一开始漏掉了这一点!唯一的方法,我可以得到?钻石符号出现是通过使用我的第二台机器没有国际字体。我不得不手动将控制台字体添加到注册表中,但是在windows控制台中显示utf字符集存在严重的问题。在我的windows 2003电脑上,我必须做以下操作:Start -> Control Panel -> Regional and Language Options -> Advanced -> Language for non-Unicode programs -> Chinese
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 如何在C++中正确地将我的语言字符输出到HTML文件中
- Java 和其他语言在生成子序列时的输出差异
- vtkArrayCalculator语言 - 访问输出时出现分段错误
- 如何在GDB/MI中获取-Interpreter语言 - Exec的输出
- 特定于域的语言工具 Visual Studio 2012 输出C++
- 音频输出C语言(新手)
- 如何用从右到左的语言进行输出
- (c++).非unicode语言(简体中文)输入/输出
- QTextDocument, QPdfWriter语言 - 如何缩放输出
- 相同的语言环境,不同的输出
- 在 C 语言中传递函数输出不正确