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
基础教程推荐
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
