如何在C控制台中打印wchar_t *?

时间:2013-07-22 02:56:04

标签: c++ utf-8 console mingw netbeans-7

我正在使用Netbeans 7.3和MinGW编译器

    #include <iostream>

    using namespace std;

    int main()
    {
        wchar_t a[] = L"std";
        wchar_t b[] = L"Стандарт";
        wcout << a;
        wcout << b;      // not printed
        return 0;
    }

输出:标准 请帮帮我,如何打印?

4 个答案:

答案 0 :(得分:1)

std::locale::global(std::locale(""));
std::wcout << L"Стандарт";

答案 1 :(得分:0)

编译代码时,我收到一条错误消息,b []中的字符在所选编码中是非法的,并将其更改为UTF-8以防止数据丢失。

答案 2 :(得分:0)

    #include <iostream>       
    using namespace std;

    int main()
    {
            wchar_t a[] = L"std";
            wchar_t b[] = L"Стандарт";
            std::locale loc("");
            std::wcout.imbue(loc);
            wcout << a;
            wcout << b;      // not printed
            return 0;

    }

答案 3 :(得分:-1)

你试过wprintf(“%s”,b)吗? 不确定c ++的标准io如何支持宽字符。