basic_fstream::open

To open or re-open a file stream for input or output.

void open (const char* s, ios_base::openmode = ios_base::in | ios_base::out);

Remarks

You would use the function open() to open a basic_fstream object and associate it with a file. You may use open() to reopen a file and associate it if the object was closed but not destroyed.

If an attempt is made to open a file in an inappropriate file opening mode, the file will not open and a test for the object will not give false, therefore use the function is_open() to check for file openings.

There is no return value.

Table 1. Legal file opening modes
Opening Modes stdio equivalent
Input Only  
ios:: in "r"
ios:: binary | ios::in "rb"
Output only  
ios::out "w"
ios::binary | ios::out "wb"
ios::out | ios::trunc "w"
ios::binary | ios::out | ios::trunc "wb"
ios::out | ios::app "a"
Input and Output  
ios::in | ios::out "r+"
ios::binary | ios::in | ios::out "r+b"
ios:: in | ios::out | ios::trunc "w+"
ios::binary | ios::in | ios::out | ios::trunc "w+b"
ios::binary | ios:: out | ios::app "ab"
See Also

For an example, see Example of basic_fstream::rdbuf() usage.