fstream::open() Unicode or Non-Ascii characters don't work (with std::ios::out) on Windows

后端 未结 2 1475
借酒劲吻你
借酒劲吻你 2021-01-14 06:15

In a C++ project, I want to open a file (fstream::open()) (which seems to be a major problem). The Windows build of my program fails miserably.

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 06:58

    In Microsoft implementations of STL, there's a non-standard extension (overload) to allow unicode support for UTF-16 encoded strings.

    Just pass UTF-16 encoded std::wstring to fstream::open(). This is the only way to make it work with fstream.

    You can read more on what I find to be the easiest way to support unicode on windows here: http://utf8everywhere.org/

提交回复
热议问题