/* This program uses class Strings to copy a file.

   Output(screen):         Prompts for input
   Input(keyboard):        The name of an input file, stored in
                           InputFileName; and the name of an output
                           file, stored in OutputFileName
   Input(InputFileName):   Characters in the file, line by line
   Output(OutputFileName): All the input characters
------------------------------------------------------------------*/

#include <iostream.h>                    // cin, cout, <<, >>
#include <fstream.h>                     // fstream, <<, >>
#include <stdlib.h>                      // exit()

#include "Strings.h"                     // class Strings

int main(void)
{                                        // introductory message
   cout << "\nThis program prompts for the name of an input file"
        << "\n\tand the name of an output file and makes a"
        << "\n\tcopy of the input file in the output file.\n";

   Strings
      InputFileName,                     // user-entered input file
      OutputFileName;                    // user-entered output file

   cout << "\nPlease enter the name of the input file: ";
   InputFileName.GetLine(cin);           // get name of input file

   fstream
      InStream(InputFileName, ios::in);  // open it for input

   if (InStream.fail())                  //    check that it worked
   {
      cerr << "\n*** Unable to open file '"
           << InputFileName << "' !\n";
      exit (1);
   }

   cout << "\nPlease enter the name of the output file: ";
   OutputFileName.GetLine(cin);          // get name of output file

   fstream
      OutStream(OutputFileName, ios::out);// open it for output...

   if (OutStream.fail())                 // checking, as always
   {
      cerr << "\n*** Unable to open file '"
           << OutputFileName << "' !\n";
      exit (1);
   }

   Strings
      Line;                              // container for a line of input

   Line.GetLine(InStream);               // read the first line

   while (!InStream.eof())               // while not end-of-file
   {
      OutStream << Line << endl;         // write the line
      Line.GetLine(InStream);            // read the next line
   }                                     // end while

   InStream.close();                     // close input and output files
   OutStream.close();
   cout << "\nCopy completed.\n";        // user feedback

   return 0;                             // successful termination
}
