//
//   ###  io_help.h  ###
//

#ifndef IOHELP_H
#define IOHELP_H

#include<iostream>   // cout & ios
#include<fstream>    // ifstream & ofstream
#include<cstdlib>     // exit

using namespace std;

// declare input files as type ifstream.  ( i.g.:  ifstream f_in; )
// declare output files as type ofstream. ( i.g.:  ofstream f_out; )
// close all opened files with the command close.  ( i.g.: f_in.close(); )


// The first two functions in this file were writen by Dr. Thomas Anastasio
// of the UMBC computer science department

//// CheckArguments(int argc, char**argv) --> void
// Exits with appropriate message if argc != 2 
void CheckArguments(int argc, char** argv)
{
// usage example-  CheckArguments(argc, argv);
if (argc != 2)
    {
      cout << "Usage: " <<
	argv[0] << " infile\n";
      exit(1);
    }
}

//// OpenInputFile(ifstream &, char*) --> void
// Connects file 'name' to stream 'in' as an input file. 
// Exits if unsuccessful.
void OpenInputFile(ifstream & in, char* name)
// usage example-  OpenInputFile("filename");
{
  in.open(name,ios::in);
  if (!in)
    {
      cout << "Unable to open file " << name << endl;
      exit(1);
    }
}

//// OpenOutputFile(ofstream &, char*) --> void
// Connects file 'name' to stream 'out' as an output file. 
// Exits if unsuccessful.
void OpenOutputFile(ofstream & out, char* name)
// usage example-  OpenOutputFile("filename");
{
  out.open(name, ios::out);
  if (!out)
    {
      cout << "Unable to open file " << name << endl;
      exit(1);
    }
}

#endif


