This is an old compiler.
Well, 2 years old, and that can be a long time when we get a new
standard every second year.
Essentially the maintenance of MinGW g++ has been passed from the
original MinGW project (where I believe you downloaded that compiler) to
the MinGW-64 project.
> And this is the message I get trying to compile your code:
>
>
> main.cpp: In function 'void init_streams()':
> main.cpp:15:32: error: '_O_WTEXT' was not declared in this scope
> _setmode( _fileno( stdin), _O_WTEXT );
By inspection of the headers of that compiler's standard library, in
order to get a definition of `_O_WTEXT` with this compiler you need to
define `__MSVCRT_VERSION__` as equal or greater than `0x0800`.
Also, with `-std=c++11` option you need to explicitly tell it to not
define `__STRICT_ANSI__`, in order to get a definition of `_fileno`.
Which with this compiler's library is defined by the header that I
forgot to include, namely `<stdio.h>`.
It's weird that a compiler whose one and only purpose was to work in
Windows, doesn't. Anyway, the good news is that the newer g++ compilers
don't have these quirks. At least not the ones from MinGW-64.
Be that as it may, the following build command works for me, with g++
5.3.0-3 from the old MinGW project:
---------------------------------------------------------------------
[H:\forums\clc++\unicode in windows console]
> g++ --version
g++ (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[H:\forums\clc++\unicode in windows console]
> g++ _setmode.cpp -std=c++11 -D __MSVCRT_VERSION__=0x0800
-U__STRICT_ANSI__
[H:\forums\clc++\unicode in windows console]
> a
Every 日本国 кошка likes Norwegian blåbærsyltetøy!
What’s your name? Særskrevne Påske Nøtter
Pleased to meet you, Særskrevne Påske Nøtter!
[H:\forums\clc++\unicode in windows console]
> _
---------------------------------------------------------------------
To avoid having to write all that every time, you can define the parts
that you'd otherwise have to repeat, as an environment variable.
Or, make a script or alias for the g++ invocation.
> main.cpp: In function 'int main()':
> main.cpp:24:21: error: converting to execution character set: Illegal
> byte sequence
> auto const& s = L"Every ??? ????? likes Norwegian blåbærsyltetøy!";
> ^
> main.cpp:28:14: error: converting to execution character set: Illegal
> byte sequence
> wcout << L"What's your name? ";
You just need to save your .cpp file with the encoding that g++ expects.
By default that's UTF-8.
And better make that UTF-8 with BOM, so that Visual C++ will understand
that it's UTF-8 by default.
> I've removed all C++11 flavours and I've added
>
> #include <cstdio>
>
> to turn off a couple of errors about finding stdin and stout.
Sorry about that, I plain forgot to include that header. :(
By the way it should be `<stdio.h>`.
The `<cstdio>` header may not necessarily provide unqualified names,
e.g. with that header one may have to write `std::stdin` instead of just
`stdin`.
> The problem is that my compiler cannot find _O_WTEXT
> and that it doesn't recognize the format L"..." string