std::basic_filebuf<CharT,Traits>::is_open
来自 cppreference.cn
< cpp | io | basic filebuf
bool is_open() const; |
||
如果最近一次调用 open() 成功,并且此后没有调用过 close(),则返回 true。
目录 |
[edit] 参数
(无)
[edit] 返回值
如果关联的文件已打开,则返回 true,否则返回 false。
[edit] 注意
此函数通常由 std::basic_fstream::is_open() 调用。
[edit] 示例
运行此代码
#include <fstream> #include <iostream> int main() { std::ifstream fs("test.txt"); std::filebuf fb; fb.open("test.txt", std::ios_base::in); std::cout << std::boolalpha << "direct call: " << fb.is_open() << '\n' << "through streambuf: " << fs.rdbuf()->is_open() << '\n' << "through fstream: " << fs.is_open() << '\n'; }
输出
direct call: true through streambuf: true through fstream: true
[edit] 参见
打开文件并将其配置为关联的字符序列 (公共成员函数) | |
刷新放置区缓冲区并关闭关联的文件 (公共成员函数) |