8.2.2. File Modes

Image

Each stream has an associated file mode that represents how the file may be used. Table 8.4 lists the file modes and their meanings.

Table 8.4. File Modes

Image

We can supply a file mode whenever we open a file—either when we call open or when we indirectly open the file when we initialize a stream from a file name. The modes that we can specify have the following restrictions:

out may be set only for an ofstream or fstream object.

in may be set only for an ifstream or fstream object.

trunc may be set only when out is also specified. ...

Get C++ Primer, Fifth Edition 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.