std::basic_ifstream<CharT,Traits>::open
来自cppreference.com
< cpp | io | basic ifstream
| void open( const char *filename, ios_base::openmode mode = ios_base::in ); |
(1) | |
| void open( const std::filesystem::path::value_type *filename, ios_base::openmode mode = ios_base::in ); |
(2) | (C++17 起) |
| void open( const std::string &filename, ios_base::openmode mode = ios_base::in ); |
(3) | (C++11 起) |
| void open( const std::filesystem::path &filename, ios_base::openmode mode = ios_base::in ); |
(4) | (C++17 起) |
将名为 filename 的文件打开并与文件流关联。
失败时调用 setstate(failbit) 。
| 成功时调用 clear() 。 | (C++11 起) |
1-2) 等效地调用 rdbuf()->open(filename, mode | ios_base::in). (该调用效果上的细节见 std::basic_filebuf::open )。仅若 std::filesystem::path::value_type 非 char 才提供重载 (2) 。 (C++17 起)
3-4) 等效地调用 (1-2) ,如同以 open(filename.c_str(), mode) 。
参数
| filename | - | 要打开的文件名 | ||||||||||||||||
| mode | - | 指定打开模式。它是位掩码类型,定义下列常量:
| ||||||||||||||||
返回值
(无)
示例
| 本节未完成 原因:暂无示例 |
参阅
| 检查流是否有关联文件 (公开成员函数) | |
| 关闭关联文件 (公开成员函数) | |
| 打开文件并配置它为关联字符序列 ( std::basic_filebuf<CharT,Traits> 的公开成员函数) |