//FILE I/O EXERCISE

#include <fstream>
#include <iostream>
#include <string>
#include <deque>

using namespace std;

int main() 
{
	//****************
	// output data to file
	// ***************
#if 1
	ofstream outfile("names.txt", ofstream::app );
	// opening file for appending
	//ofstream appfile("names.txt", ofstream::app);

	/* Insert integers
	for( int i=0; i<10; i++ ) {
		outfile << i << endl;
	}
	*/

	outfile << "Chulsoo" << endl;
	outfile << "Myongji" << endl;
	outfile << "Jiyoo" << endl;

	outfile.close();
#endif
	//****************
	// read data from file
	// ***************

	deque<string> names;

	ifstream inputfile("names.txt");
	string line;
	while( ! inputfile.eof() ) {
		getline( inputfile, line );
		names.push_front( line );
	}
	inputfile.close();

	cout << "Names in namse.txt" << endl;
	for( auto p = names.begin(); p != names.end(); p++ )
		cout << *p << endl;

	system("pause");
}
