【问题标题】:Unicode Windows console application (WxDev-C++/minGW 4.6.1)Unicode Windows 控制台应用程序 (WxDev-C++/minGW 4.6.1)
【发布时间】:2014-05-03 22:34:18
【问题描述】:

我正在尝试制作简单的多语言 Windows 控制台应用程序,仅用于教育目的。我在 WxDev-C++/minGW 4.6.1 中使用 c++ lahguage,我知道这种问题被问了百万次。我可能搜索了整个互联网,也可能查看了所有论坛,但没有任何帮助。

这是示例工作代码:

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    /* English version of Hello world */
    wchar_t EN_helloWorld[] = L"Hello world!";
    wcout << EN_helloWorld << endl;

    cout << "\nPress the enter key to continue...";
    cin.get();
    return 0;
}

在我尝试放入一些非常宽泛的字符(例如“Ahoj světe!”)之前,它非常有效。问题在于“ě”,即十六进制 unicode 中的“011B”。编译器给我这个错误:“非法字节序列。”

不工作的代码:

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    /* Czech version of Hello world */
    wchar_t CS_helloWorld[] = L"Ahoj světe!"; /* error: Illegal byte sequence */
    wcout << CS_helloWorld << endl;

    cout << "\nPress the enter key to continue...";
    cin.get();
    return 0;
}

我听说过诸如#define UNICODE/_UNICODE、-municode 或为旧版 minGW 下载包装器之类的事情。我试过了,但它不起作用。可能是我不知道如何正确使用它们。无论如何,我需要一些帮助。在 Visual Studio 中,这很简单。

非常感谢您的回复。

【问题讨论】:

    标签: c++ windows unicode console mingw


    【解决方案1】:

    显然,使用 UTF-16 的标准输出流在 MinGW 中不起作用。

    我发现我可以使用 Windows API,也可以使用 UTF-8。 See this other answer 获取代码示例。

    【讨论】:

      【解决方案2】:

      这是一个answer,不确定这是否适用于 minGW。

      还有一些特定于 minGW here的细节

      【讨论】:

        猜你喜欢
        • 2010-12-27
        • 2014-11-21
        • 2012-10-17
        • 1970-01-01
        • 2016-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多