fstream open函数中的第三个参数是什么意思

What means third parameter in fstream open function

fstream open函数中的第三个参数是什么意思?我试着在网上搜索它,但没有关于三个参数的重载版本的明确解释。 这是来自 fstream 文件:

void open(const char* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
    int _Prot = (int) ios_base::_Openprot) { // open a C stream with specified mode

如果这个参数在某些情况下真的是程序员需要的,或者只是为了实现方便?

就C++标准而言,there is no third parameter。为了一些 implementation-specific 方便,您的实现可能有一个默认参数,但 C++ 标准没有这样的参数。

第三个参数记录在Microsoft's documentation for the basic_fstream::open() method:

Parameters

_Filename
The name of the file to open.

_Mode
One of the enumerations in ios_base::openmode.

_Prot
The default file opening protection, equivalent to the shflag parameter in _fsopen, _wfsopen.

The argument shflag is a constant expression consisting of one of the following manifest constants, defined in Share.h.

_SH_COMPAT
Sets Compatibility mode for 16-bit applications.

_SH_DENYNO
Permits read and write access.

_SH_DENYRD
Denies read access to the file.

_SH_DENYRW
Denies read and write access to the file.

_SH_DENYWR
Denies write access to the file.

std::ios_base::_Openprot 的值定义为 _SH_DENYNO