public member function

std::filebuf::is_open

<fstream>
bool is_open ( );
Check if a file is open
The function returns true if a previous call to open succeeded and there have been no calls to the member close since, meaning that the filebuf object is currently associated with a file.

Parameters

none

Return Value

true if a file is open, i.e. associated to this stream buffer object.
false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// is_open () example
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  ifstream is;
  filebuf * fb;

  fb = is.rdbuf();
  fb->open ("test.txt",ios::in);

  if ( fb->is_open() )
    cout << "file is open.\n";
  else
    cout << "file is not open.\n";

  fb->close();

  return 0;
}


Basic template member declaration

( basic_filebuf<charT,traits> )
 
bool is_open ( );


See also