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

后端 未结 2 1491
借酒劲吻你
借酒劲吻你 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 07:00

    Using the standard APIs (such as std::fstream) on Windows you can only open a file if the filename can be encoded using the currently set "ANSI Codepage" (CP_ACP).

    This means that there can be files which simply cannot be opened using these APIs on Windows. Unless Microsoft implements support for setting CP_ACP to CP_UTF8 then this cannot be using Microsoft's CRT or C++ standard library implementation.

    (Windows has had a feature called "short" filenames where, when enabled, every file on the drive had an ASCII filename that can be used via standard APIs. However this feature is going away so it does not represent a viable solution.)

提交回复
热议问题