/* Lecture code 6.0
 *
 * STL Algorithms to load data from a file and average the values.
 * Demonstrates istream_iterator and accumulate, as well as exactly
 * how concise the STL can be!
 *
 * This code requires a data file numbers.txt to be in the same directory
 * as the program.
 */

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>  // For istream_iterator, back_inserter
#include <algorithm> // For copy
#include <numeric>   // For accumulate
using namespace std;

int main()
{
	ifstream input("numbers.txt");
	vector<int> myVector;

	/* Load the contents of the file into the vector. */
	copy (istream_iterator<int>(input), istream_iterator<int>(), back_inserter(myVector));

	/* Calculate the average value. */
	cout << accumulate(myVector.begin(), myVector.end(), 0.0) / myVector.size() << endl;
	return 0;
}