#include <iostream>
#include <fstream>
using namespace std;

void main (void)
{	
	int i, data[5];
	fstream file1; //fstream is used to declare a file 

	file1.open("test.dat",ios::out);	//the file test.dat is opened for output, any existing data in the file will be overwritten
	
	cout<<"this program will output data to be stored to a file on disk\n\n";
	for (i=0;i<5;i++)
	{
		cout<<"enter value:";
		cin>>data[i];
		file1<<data[i]<<"\n";	//the information is written to the file
	}
	file1.close(); //the file is closed

	for (i=0;i<5;i++)	// this loop fills the array data with zeroes
		data[i]=0;
	cout<<"the array data currently contains the following information:\n";
	for(i=0;i<5;i++)
		cout<<data[i]<<"\n";

	file1.open("test.dat",ios::in);	//the file test.dat is opened for input (to read the data stored in it)

	for (i=0;i<5;i++)	//this loop reads the data form the file and stores it in the array
		file1>>data[i];

	cout<<"the array has now been filled with data form the file.\n";
	cout<<"the array data currently contains the following information:\n";
	for (i=0;i<5;i++)
		cout<<data[i]<<"\n";
	file1.close();	//the file is closed
}