// ofstreamDemo.cc  P. Conrad, 4/8/2004 for CISC181

#include <iostream>

#include <fstream> // for ifstream and ofstream

using std::cout;
using std::cin;
using std::ios;
using std::cerr;
using std::endl;

int main ()
{


  int x=3;        // x and y are variables just for demonstration purposes 
  double y=4.5;
  
  // open the output file


  ofstream outfile("output.txt",ios::out);
  
  if (!outfile) // overloaded ! operator to check status of file
    {
      cerr << "File output.txt could not be opened: ";
      exit(-1);
    }
  
  /* write some output to the file */
  
  
  outfile << "This output is going to the file output.txt." << endl;
  
  cout << "This output is going to the terminal." << endl;
  cout << "I can still write to the terminal in the same program" << endl;
  cout << "that I am writing to a file." << endl;
  
  outfile << "I can also print the value of variables to a file." << endl;
  outfile << "for example, x=" << x << ", y=" << y << endl;
  outfile << "Bye now!" << endl;
  
  /* close the output file */
  
  outfile.close();
  
  return 0;
}


