Reading from a File
#include <fstream> #include <iostream> using namespace std; int main () { char data[80]; ofstream outfile; outfile.open("students.dat"); cout << "Writing to the file" << endl; cout << "Enter class name: "; cin.getline(data, 80); outfile << data << endl; cout << "Enter number of students: "; cin >> data; cin.ignore(); outfile << data << endl; outfile.close(); ifstream infile; cout << "Reading from the file" << endl; infile.open("students.dat"); infile >> data; cout << data << endl; infile >> data; cout << data << endl; infile.close(); return 0; }