16. Write a program that uses functions to perform the following
operations:
a. To copy
contents of one file into another file.
/* COPY
CONTENTS OF ONE FILE INTO ANOTHER FILE.
*/
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
fstream ifile;
fstream ofile;
char fname[30],st[30];
ofile.open("temp.cpp",ios::out);
cout<<"\n Enter the existing file name";
cin>>fname;
ifile.open(fname,ios::in);
while(ifile)
{
ifile.getline(st,30);
ofile<<st;
}
ifile.close();
ofile.close();
cout<<"\n The contents of the copied file are\n";
fstream tfile;
tfile.open("temp.cpp",ios::in);
char str[30];
while(tfile)
{
tfile.getline(str,30);
cout<<str;
}
}
0 comments:
Post a Comment