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: "clients.txt", ios::out );

Image Error-Prevention Tip 14.2

Some operating systems allow you to open the same file multiple times simultaneously. Avoid doing this because it can lead to subtle problems.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.