// writetofile.cpp - how to write to a text file
#include <iostream>
#include <string>
// We need to include fstream to have access to file manipulation
// commands, and the ofstream class. 
#include <fstream>

int main() {
  using namespace std;

  // declaring variables to hold data gathered by user
  string classCode;
  string instructor;
  int numStudents;
  int classRoom;

  // creating an ofstream variable and associating a file with it.
  // specifying a file that doesn't exist will create a new one.
  ofstream outFile;
  outFile.open("class_info.txt");
  
  // gathering data using cin
  cout << "Enter the class code: ";
  cin >> classCode;
  cout << "Enter the instructors last name: ";
  cin >> instructor;
  cout << "Enter the # of students: ";
  cin >> numStudents;
  cout << "Enter the class room: ";
  cin >> classRoom;

  // outputting to the screen using cout
  cout << "\n";
  cout << "Class Code: " << classCode;
  cout << "\nInstructor: " << instructor;
  cout << "\n# of Students: " << numStudents;
  cout << "\nClass Room: " << classRoom << endl;

  // outputting to a file using ofstream object
  outFile << "Class Name: " << classCode;
  outFile << "\nInstructor: " << instructor;
  outFile << "\n# of Students: " << numStudents;
  outFile << "\nClass Room: " << classRoom;

  outFile.close();

}
