Well, a wide output stream translates from the wide encoding (UTF-16 in
Windows) to the external byte encoding (the ANSI codepage in Windows).
Windows only recently, in the May 2019 update of Windows 10, got support
for UTF-8 as ANSI encoding. To enable that for your application you can
add a special manifest setting with a brittle spaces-are-significant
syntax. See <url:
https://alfps.wordpress.com/2020/01/03/a-windows-h-wrapper-for-utf-8-windows-apps/>
for details.
Alternatively, if you're only using Visual C++ and don't plan on
supporting other compilers, then you can use `_setmode`. See (currently)
<url:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=vs-2019>.
Third alternative, there is a Boost sublibrary for UTF-8 i/o. When I
checked it out, right around its Boost adoption, because its author
referred to a blog article of mine, it was brittle and with some trivial
nasty bugs (like forgetting to remove carriage return in input). But
maybe it has benefited from Boost-ing, and it may do the job for you.
<rant>
This is IMO all very Windows-specific, not C++, i.e. off-topic here,
except for iostreams' curious lack of support for encodings, which is
needed critical functionality, and the ditto curious forced use of
[beep] archaic & over-engineered complex limited locale functionality,
which is not needed and cause a very undesired inefficiency.
</rant>
- Alf