/* Program 5.6.1 from C++ Programming Lecture notes  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2023 */

/* This program copies itself to "Copy_of_5" and to the screen. */ 

#include <iostream>
#include <fstream>

using namespace std;

void copy_to(ifstream& in, ofstream& out);

/* MAIN PROGRAM: */
int main()
{
	ifstream in_stream;
	ofstream out_stream;

	in_stream.open("5-6-1.cpp");
	out_stream.open("Copy_of_5");
	copy_to(in_stream, out_stream);	
	out_stream.close();
	in_stream.close();

	return 0;
}
/* END OF MAIN PROGRAM */

/* FUNCTION TO COPY ONE FILE FROM ANOTHER: */
void copy_to(ifstream& in, ofstream& out)
{
	char character;

	in.get(character);
	while (!in.fail())
	{
		cout << character;
		out.put(character);
		in.get(character);
	}
}
/* END OF FUNCTION */
