Unless data can be stored safely, it will disappear when the program exits. Therefore, it is necessary to write to and read from files. Just like the console <iostream> interface, the file uses <fstream>. It needs to be included with your other standard library resources. A related library that is sometimes needed is <sstream>.
#include <fstream>
#include <sstream>
When a file is open for reading or writing, be sure to close it when done. The methods/functions in fstream are a part of a class. The three most used classes are:
- ifstream – for input
- ofstream – for output
- fstream – for a file that can be used for either, be careful of this.
I used the rainfall program that was done in our class to show how to use File I/O.
Please let me know if you have any questions.
I will right away grab your rss feed as I can’t in finding your e-mail subscription hyperlink or newsletter service. Do you have any? Please permit me recognise so that I could subscribe. Thanks.