且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

fstream :: open()Unicode或Non-Ascii字符在Windows上不起作用(使用std :: ios :: out)

更新时间:2023-01-03 09:46:13

在Windows上使用标准API(例如std :: fstream),如果文件名可以使用当前设置的"ANSI代码页"进行编码,则只能打开文件"(CP_ACP).

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).

这意味着可能存在在Windows上使用这些API无法完全打开的文件.除非Microsoft支持将CP_ACP设置为CP_UTF8,否则不能使用Microsoft的CRT或C ++标准库实现.

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具有一个名为短"文件名的功能,启用该功能后,驱动器上的每个文件都具有一个可通过标准API使用的ASCII文件名.但是,此功能已不复存在,因此并不代表可行的解决方案. )

(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.)