Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't this simple program work? [duplicate]

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
like image 803
Egor Tensin Avatar asked Jun 07 '26 04:06

Egor Tensin


1 Answers

I think this is because wcout converts to narrow characters.

See this other question about this topic.

Another good link.

like image 169
Benoit Avatar answered Jun 08 '26 20:06

Benoit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!