为什么这个简单的程序不起作用?

时间:2013-12-04 14:31:50

标签: c++ visual-c++ unicode

我正在尝试解决有关Unicode在Windows控制台应用程序中的工作方式的所有问题。为什么这个简单的程序不起作用?

#include <iostream>

int wmain(int argc, const wchar_t* const argv[])
{
    for (int i = 1; i < argc; ++i)
        std::wcout << argv[i] << std::endl;

    return 0;
}

编译

>cl /EHsc /D _UNICODE /D UNICODE /Zc:wchar_t test.cpp

程序生成

> test.exe 1 2 3 abc абв
1
2
3
abc

第五个参数在哪里?我必须提到абв适用于GetACP()GetConsoleCP()&amp; GetConsoleOutputCP()代码页(1251,866和866)。有趣的是,该程序(在某种程度上)与这些代码页之外的字符一起工作:

> test.exe Sæter
Sцter

可是:

> test.exe абв Sæter

1 个答案:

答案 0 :(得分:1)

我认为这是因为wcout会转换为较窄的字符。

有关此主题,请参阅this other question

Another good link

相关问题