5.9.3.2. Iostream: Writing to a File (optional)

To use the things described here, #include the <fstream> library.

ofstream out(path);

ofstream is a type. This statement creates an ofstream object called out that writes to the file described by string path.

out << x;

Do with an open ofstream object all of the same things that you can do with cout.

out.close()

Use this to close file out when you are done writing to it.