//The 'fstream package gives access to file handling routines.
//Note that '<<' and '>>' work for files, too.

/*This program copies file1.dat to a user specified file,
 putting each word on a separate line.
*/ 

#include<iostream>
#include<fstream>
#include<string>

using std::cout; using std::cin;
using std::string; using std::endl;
using std::ifstream; using std::ofstream;

int main()
{
	
	string s, user_file;
	cout<<"\nWhat is name of the file to write to? ";
	cin>>user_file;
	cout<<endl<<"The following is being written to "<<user_file<<":";
	cout<<endl<<endl;
	ifstream infile("file1.dat");
	ofstream outfile(user_file.c_str()); //Make user_file into a C-style 
					     // string.

	while(infile>>s)
	{
		cout<<s<<endl;
		outfile<<s<<endl;
	}
	infile.clear();
	return 0;
	
}
