Syntax:
#include <fstream> void fstream::open(const char *filename, openmode mode = default_mode);
The function open() is used with file streams. It opens filename and associates it with the current stream. The mode parameter defaults to ios::in for ifstream, ios::out for ofstream, and ios::in|ios::out for fstream. If open() fails, the stream is put into a non-good state which may be checked. For example:
ifstream inputStream; inputStream.open("file.txt"); if( !inputStream ) { cerr << "Error opening input stream" << endl; } // or if ( inputStream ) { // use inputStream }
Related Topics: I/O Constructors, close, C++ I/O Mode Flags