#2001 ostream text mode does not use codecvt facets! (UTF-16)


MinGW has not (as yet) implemented the <codecvt> C++11 header. (IDK why online resources say this would require a change in the library DLL.)

So I wrote my own.

The problem:

locale loc( locale(), codecvt_utf16 <wchar_t> );
wofstream f( "foo.txt" );
f.imbue( loc );

f << "Hello world\n";

This produces an output sequence terminating in

0D 0A 00

Instead of the (correct)

0D 00 0A 00

I could, of course, just open the file in binary mode, and get:

0A 00

But that is beside the point.

Is there a reason that the text mode newline translation is not using the codecvt facet to insert characters in the output stream?


  • Earnie Boyd

    Earnie Boyd - 2013-07-03
    • status: unread --> open
    • Type: Bug --> Support
  • Earnie Boyd

    Earnie Boyd - 2013-07-03

    Which shell are you executing this from?
    Text mode is a Microsoft thing, it is their runtime we use for it.
    What locale (a.k.a. codepage) do you have your system set to?
    Please add a SSCCE to this issue.

  • Michael Thomas Greer

    Standard Windows Console (cmd.exe) shell; default locale/codepage. Shouldn't make a difference, no? I'm interacting directly with file.

    I haven't actually tested using another locale. Making non-default locales really work on Windows requires Boost and ICU.

    But if I understand correctly, I must apply locale conversions in more than one place?

    A short example will be difficult with a codecvt facet... give me a bit to cut out everything that is not needed...

    [edit] Ok, added as attachment

    Last edit: Michael Thomas Greer 2013-07-03

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks