cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : filebuf : is_open
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
filebuf
· filebuf::filebuf
· filebuf::~filebuf
member functions:
· filebuf::close
· filebuf::is_open
· filebuf::open
virtual members:
· filebuf::imbue
· filebuf::overflow
· filebuf::pbackfail
· filebuf::seekoff
· filebuf::seekpos
· filebuf::setbuf
· filebuf::showmanyc
· filebuf::sync
· filebuf::uflow
· filebuf::underflow

-

filebuf::is_open public member function
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

// 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

filebuf::open Open file (public member function)
filebuf::close Close file (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us