Boost C++ 库

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

basic_stream_file::open (4 个重载之一) - Boost C++ 函数库
PrevUpHomeNext

从 basic_file 继承而来。

使用指定路径打开文件。

void open(
    const char * path,
    file_base::flags open_flags);

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

参数

路径

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

open_flags

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

异常

boost::system::system_error

失败时抛出。

必须指定以下 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
示例
boost::asio::stream_file file(my_context);
file.open("/path/to/my/file", boost::asio::stream_file::read_only);

PrevUpHomeNext