How do I print UTF-8 from c++ console application on Windows(如何从 Windows 上的 C++ 控制台应用程序打印 UTF-8)
问题描述
用于在英文 Windows(XP、Vista 或 7)上使用 Visual Studio 2008 编译的 C++ 控制台应用程序.是否可以打印到控制台并使用 cout 或 wcout 正确显示 UTF-8 编码的日语?
For a C++ console application compiled with Visual Studio 2008 on English Windows (XP,Vista or 7). Is it possible to print out to the console and correctly display UTF-8 encoded Japanese using cout or wcout?
推荐答案
这应该有效:
#include <cstdio>
#include <windows.h>
#pragma execution_character_set( "utf-8" )
int main()
{
SetConsoleOutputCP( 65001 );
printf( "Testing unicode -- English -- Ελληνικά -- Español -- Русский. aäbcdefghijklmnoöpqrsßtuüvwxyz
" );
}
不知道它是否会影响任何东西,但源文件保存为 Unicode(带签名的 UTF-8)-代码页 65001 在 FILE -> 高级保存选项....
Don't know if it affects anything, but source file is saved as Unicode (UTF-8 with signature) - Codepage 65001 at FILE -> Advanced Save Options ....
项目 -> 属性 -> 配置属性 -> 常规 -> 字符集 设置为使用 Unicode 字符集.
Project -> Properties -> Configuration Properties -> General -> Character Set is set to Use Unicode Character Set.
有人说您需要将控制台字体更改为 Lucida Console,但在我这边,它同时显示为 Consolas 和 Lucida Console.
Some say you need to change console font to Lucida Console, but on my side it is displayed with both Consolas and Lucida Console.
这篇关于如何从 Windows 上的 C++ 控制台应用程序打印 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Windows 上的 C++ 控制台应用程序打印 UTF-8


基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01