/* Read fills a vector<T> with input from a stream.
 *
 * Receives:     type parameter T,
 *               an istream and a vector<T>
 * Precondition: operator >> is defined for type T
 * Passes back:  the modified istream and the modified vector<T>
 *****************************************************************/

template <class T>
void Read(istream & in, vector<T> & theVector)
{
   T inputValue;

   for (;;)
   {
      in >> inputValue;
      if (in.eof()) break;
      theVector.push_back(inputValue);
   }
}


/* Read fills a vector<T> with input from an ifstream connected
 * to a file named fileName.
 *
 * Receives:     type parameter T,
 *               fileName, a string,
 *               and a vector<T>
 * Precondition: operator >> is defined for type T
 * Passes back:  the modified vector<T>
 *****************************************************************/

template <class T>
void Read(string fileName, vector<T> & theVector)
{
   ifstream inStream(fileName.data());
   if (!inStream.is_open())
   {
      cerr << "\n***Read(): unable to open " << fileName << endl;
      exit(1);
   }

   T inputValue;
   for (;;)
   {
      inStream >> inputValue;
      if (inStream.eof()) break;
      theVector.push_back(inputValue);
   }
   inStream.close();
 }

/* Print writes a vector<T> to a stream.
 *
 * Receives:     type parameter T
 *               an ostream and a vector<T>
 * Precondition: operator << is defined for type T
 * Passes back:  the modified ostream *****************************************************************/

template <class T>
void Print(ostream & out, const vector<T> & theVector)
{
   for (int i = 0; i < theVector.size(); i++)
      out << theVector[i] << ' ';
}

