... Data can be written anywhere in the file. | |
ios::in |
Open a file for input. |
ios::out |
Open a file for output. |
ios::trunc |
Discard the file’s contents (this also is the default action for ios::out ). |
ios::binary |
Open a file for binary, i.e., nontext, input or output. |
14.3.2 Opening a File via the open
Member Function
You can create an ofstream
object without opening a specific file—in this case, a file can be attached to the object later. For example, the statement
ofstream outClientFile;
creates an ofstream
object that’s not yet associated with a file. The ofstream
member function open
opens a file and attaches it to an existing ofstream
object as follows:
outClientFile.open("clients.txt", ios::out);
Once again, ios::out
is the default ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.