/***
 * An input file recipe
 */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
	ifstream infile;
	string fname;
	cout << "Enter input file name: " << flush;
	cin >> fname;
	infile.open( fname.c_str() ); 
	if( !infile ) { 
		cout << "Error opening file." << endl;
		cout << endl;
	} else {
		int words_read(0); 
		string word;
		while( infile >> word ) { 
			words_read++;
		} 
		if( infile.eof() ) {
			cout << "Read " << words_read << " words."; 
			cout << endl;
		} else if( infile.fail() ) {
			cout << "ERROR reading words!";
			cout << endl;
		}
	}
	infile.close();
	return 0;
}

