public member function
<fstream>

std::basic_filebuf::is_open

bool is_open() const;
Check if file is open
Returns whether the object is currently associated to a file (i.e., open).

The function returns true if a previous call to member open succeeded and there have been no calls to member close since.

Parameters

none

Return Value

true if a file is open and associated with this file stream buffer object.
false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// filebuf::is_open() example
#include <iostream>
#include <fstream>

int main () {
  std::ifstream is;
  std::filebuf * fb = is.rdbuf();
  fb->open ("test.txt",std::ios::in);

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

  fb->close();

  return 0;
}


Data races

Accesses the basic_filebuf object.
Concurrent access to the same file stream buffer object may introduce data races.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the file stream buffer.

See also