- Files are secondary storage or persistent storage; data remains in tact after computer is shut down
- We can save input in a file so that the next time the program is run we don't have to type it in again; Lab #2
- We can save output in a file so we don't have to run the program to generate the values again; Lab #4
- All real programs use files
- Files are used in conjunction with streams; input streams and output streams (reading and writing)
- cin and cout are streams; using files is very similar (almost identical) to using cin and cout
- We include iostream.h so we can use cin and cout; we include fstream.h so we can declare file input and output streams
#include <iostream.h> // cin/cout streams
#include <fstream.h> // file streams
ofstream outFile; // declare an output file stream
cout << "This writes to the display screen";
outFile << "This writes to a disk file";