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 );
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.