Namespaces
Variants

std::basic_filebuf<CharT,Traits>:: is_open

From cppreference.net
bool is_open ( ) const ;

若最近一次对 open() 的调用成功,且此后未调用过 close() ,则返回 true

目录

参数

(无)

返回值

true 表示关联文件已打开, false 表示未打开。

注释

该函数通常由 std::basic_fstream::is_open() 调用。

示例

#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

参见

打开文件并将其配置为关联的字符序列
(公开成员函数)
刷新输出区缓冲区并关闭关联文件
(公开成员函数)