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
I think this is because wcout converts to narrow characters.
See this other question about this topic.
Another good link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With