Egor Tensin Egor Tensin - 3 months ago 11
C++ Question

Why doesn't this simple program work?

I'm trying to sort out everything concerning the way Unicode works in Windows console applications. Why doesn't this simple program work?

#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;
}


Compiled with

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


the program produces

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


Where is the fifth argument? I have to mention that
абв
fits into both my
GetACP()
and
GetConsoleCP()
&
GetConsoleOutputCP()
code pages (1251, 866 & 866). It's interesting that the program works (in a way) with the characters outside of those code pages:

> test.exe Sæter
Sцter


But:

> test.exe абв Sæter

Answer

I think this is because wcout converts to narrow characters.

See this other question about this topic.

Another good link.

Comments