Once the user enters the end-of-file indicator, main
terminates. This implicitly invokes outClientFile
’s destructor, which closes the clients.txt
file. You also can close the ofstream
object explicitly, using member function close as follows:
outClientFile.close();
Error-Prevention Tip 14.3
Always close a file as soon as it’s no longer needed in a program