Why can't I disable a line starting with a Unicode character in Windows?

I am working on a C ++ console program that prints some text in Unicode. On Linux, it just works, but on Windows it behaves strangely: Unicode characters only display correctly until they are at the beginning std::string. If they are, the program simply stops.

Here's the abbreviation:

#include <iostream>
#include <string>

using std::cout;

int main() {
    std::string letters = "àèéìòùäöüß";
    std::string is_nice = "è bello";    // In Italian this means "is nice"

    cout << "Concatenating the strings using '+':\n";
    cout << "Unicode " + letters << "\n";
    cout << "Unicode " + is_nice << "\n";

    cout << "\n";

    cout << "Using 'cout' and 'operator<<' to print the strings:\n";
    cout << "Unicode " << letters << "\n";
    cout << "Unicode " << is_nice << "\n";
}

The source file is encoded as UTF-8. On Linux I will compile it (using g ++ 5.4.0) with

g++ -std=c++14 -Wall -Wextra Unicode.cpp -o Unicode

and on Windows (using MinGW.org GCC-6.3.0-1) with

g++ -std=c++14 -Wall -Wextra Unicode.cpp -o Unicode.exe

If I compile it and run it from Linux (in this case I use the Windows Subsystem for Linux , the version of Ubuntu that runs on Windows 10), no problem, everything works.

Windows ( cmd, PowerShell), . . , , chcp 65001, UTF-8, Lucida Console. , cout , ASCII (, 2), , , à è (, 2), . , Linux:

"+":
Unicode àééìòùäöüß

'cout' 'operator < < :
Unicode àééìòùäöüß

, Windows:

"+":
Unicode àééìòùäöüß

'cout' 'operator < < :
Unicode

. -, Unicode , , , Unicode . "" , . .

, ? ?

+4

Source: https://habr.com/ru/post/1693237/


All Articles