【发布时间】:2013-12-04 14:31:49
【问题描述】:
我正在尝试整理有关 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() 和GetConsoleOutputCP() 代码页(1251、866 和866)。有趣的是,该程序(在某种程度上)与这些代码页之外的字符一起工作:
> test.exe Sæter
Sцter
但是:
> test.exe абв Sæter
【问题讨论】:
-
如果你做
test.exe 1 2 3 abc абв > output.txt,输出文件是否正确? -
@Benoit 不是,还是没有最后一行。
-
试试这个:
printf("%d\n", argc);。你得到了什么?
标签: c++ visual-c++ unicode