// readNums.cc 
// read Numbers from a file 
// P. Conrad 02/09/06


#include <iostream>
#include <fstream> // for reading from files, or writing to files
using namespace std;

int main(void)
{

  ifstream infile("nums.dat", ios::in);

  if (!infile)
    {
      cerr << "I could not open nums.dat... sorry!" << endl;
      return 1; // indicates an error condition
    }

  int sum = 0;
  
  int x;

  infile >> x;  // instead of cin >> x, use infile >> x to read from file
  while(!infile.eof())
    {
      sum += x;
      infile >> x;  // instead of cin >> x, use infile >> x to read from file
    }

  cout << "sum = " << sum << endl;

  return 0;
}

