fstream::is_open
bool is_open ( );
fstream
  cplusplus.com  

Check if a file has been opened.
  Checks if the stream is currently associated with a valid file buffer.

Parameters.

none
 

Return Value.
  If a file has successfully been opened (i.e. the stream is associated with a valid file buffer) the member function returns true,
  otherwise false is returned.

Example.

// fstream::is_open
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  fstream filestr;
  filestr.open ("test.txt");
  if (filestr.is_open())
  {
    cout << "File successfully open";
    filestr.close();
  }
  else
  {
    cout << "Error opening file";
  }
  return 0;
}

Basic template member declaration ( basic_fstream<charT,traits> ):
bool is_open ();

See also.
  open
  fstream class


© The C++ Resources Network, 2001