Boost C++ 库

...世界上备受推崇且设计精良的C++库项目之一。 Herb SutterAndrei Alexandrescu, C++编程规范

basic_file::open (4个重载中的第2个) - Boost C++ 函数库
PrevUpHomeNext

使用指定路径打开文件。

void open(
    const char * path,
    file_base::flags open_flags,
    boost::system::error_code & ec);

此函数打开文件,以便它将使用指定的路径。

参数

路径

用于标识要打开的文件的路径名。

open_flags

一组标志,用于确定应如何打开文件。

必须指定以下 file_base::flags 值之一

  • flags::read_only
  • flags::write_only
  • flags::read_write

以下标志可以按位或运算进行添加

  • flags::append
  • flags::create
  • flags::exclusive
  • flags::truncate
  • flags::sync_all_on_write
参数

ec

用于指示发生何种错误(如果有)。

示例
boost::asio::stream_file file(my_context);
boost::system::error_code ec;
file.open("/path/to/my/file", boost::asio::stream_file::read_only, ec);
if (ec)
{
  // An error occurred.
}

PrevUpHomeNext