/***
 * An output file recipe
 */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
	ofstream outfile;
	string fname;
	bool append( false );
	cout << "Enter output file name: " << flush;
	cin >> fname;
	cout << "Append ? 0 or 1: " << flush;
	cin >> append;
	if( append ) { // append mode
		outfile.open( fname.c_str(), ios::app );
	} else { // overwrite (default open mode)
		outfile.open( fname.c_str() );
	}
	if( !outfile ) { 
		cout << "Error opening file." << endl;
	} else {
		int lines; 
		for( lines=1; lines<=10 && outfile; lines++ ) { 
			outfile << "Line " << lines << endl; 
		} 
		if( outfile.fail() ) {
			cout << "ERROR writing file." << endl;
		}
	}
	outfile.close();
	return 0;
}

