//Illustrates command-line arguments, the ".eof()" file method, and the input
//and output of strings.
//To use:
// Compile into a.out, and then execute by typing 
//	a.out fname
// at the unix prompt, where fname is the  name of a file in the current
// directory.  
//
//
#include <fstream>
#include <iostream>
#include <string>


int main(int argc, char * argv[]){
  //argc is initialized to the number of arguments specified in the
  //command-line (the command-name itself is one argument) The
  //arguments are stored in the array of strings argv.  Thus, if
  //called as a.out myfile argc gets the value 2, argv[0] the string
  //"a.out", and argv[1] the string "myfile

  if (argc < 2){// check to determine whether the input argument is provided
    cerr << "sanErr: file-name expected as command line argument\n";
    exit (1);//no file-name ==> exit the program
  }

  ifstream infile;
  infile.open(argv[1], ios::in);// open the file specified in the command line

  string s;
  while (!infile.eof()){
    infile >> s;
    cout <<"\t" << s << endl;
  }
  infile.close();
}
