I haven't seen anyone answer the part about reading from a file yet, so I'll do a quick summary.
You use ofstream to write data to a file, and ifstream to read data from a file.
It's similar to how cout and cin work, just open a file
ifstream input("file_Name.txt");
then
input >> variable;
, just like cin the symbols are turned around for reading to a variable.
The best part is that you know the order that you wrote the values into the file so you just read from the file in the same order. You might have to do some error checking in case the user tries to open the wrong file. (You get teachers who are strict about error-checking some times).
Also remember to close all files after you're done using them with the close() function;
input.close();
[The following won't be needed for your assignment]:
There is also the idea of a cursor, it's an iterator that tells the program where you last read from and makes sure things are read in order. Some times you might want to skip around in a file so look into the
tellg()
and
seekg()
functions when you have some free time.
There are also functions to read a single char
variable = input.get();
or to read an entire line
getline(input, stringVariable);
which you might also want to practice using.
http://www.cplusplus.com/reference/fstream/ifstream/