如何从 Windows 上的 C++ 控制台应用程序打印 UTF-8 [英] How do I print UTF-8 from c++ console application on Windows

查看:28
本文介绍了如何从 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)-代码页 65001FILE -> 高级保存选项....

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,但在我这边,它同时显示为 ConsolasLucida 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆