#include <fstream>void fstream::open(const char *filename,                    ios::openmode mode = ios::in | ios:: out); void ifstream::open(const char *filename,                     ios::openmode mode = ios::in); void ofstream::open(const char *filename,                     ios::openmode mode = ios:: out | ios::trunc); 

The open( ) function is a member of fstream, ifstream, and ofstream.

A file is associated with a stream by using the open( ) function. Here, filename is the name of the file, which may include a path specifier. The value of mode determines how the file is opened. It must be one (or more) of these values:


You can combine two or more of these values by ORing them together.

Including ios::app causes all output to that file to be appended to the end. This value can be used only with files capable of output. Including ios::ate causes a seek to the end of the file to occur when the file is opened. Although ios::ate causes a seek to the end of file, I/O operations can still occur anywhere within the file.

The ios::binary value causes the file to be opened for binary I/O operations. By default, files are opened in text mode.

The ios::in value specifies that the file is capable of input. The ios::out value specifies that the file is capable of output. However, creating an ifstream stream implies input, creating an ofstream stream implies output, and opening a file using fstream implies both input and output.

The ios::trunc value causes the contents of a preexisting file by the same name to be destroyed and the file is truncated to zero length.

In all cases, if open( ) fails, the stream will be false. Therefore, before using a file, you should test to make sure that the open operation succeeded.

Related functions are close( ), fstream( ), ifstream( ), and ofstream( ).

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: