Here's the prototype for the read() member function of the ifstream class:Ĭerr << 'Error - unable to open input file ' << file_name << endl Close the ifstream object once we're done reading the input.Call the read() member function of the ifstream object to read the input data.Declare an ifstream file stream object and open it for input just like you would for a text file.So we'll need an appropriate using statement or we'll need to fully qualify the class name when we use it.
The ifstream class to read the input, which is part of the standard namespace.#include at the top of the file since that header file contains the classes and member function prototypes that we'll need.To read a file that was created in binary format, we'll need to perform the following steps: But what if the data in the file was stored in a different format? Binary Input That obviously worked, and was a good option under the circumstances. Create a Student object and copy it intoĬlass_list = Student(name, gpa) Open the input file and test for failure Void Course::read_student_data(const string& file_name)Ĭhar first_name, last_name, name