Computer Science, asked by rekha4596, 1 year ago

Write a c++ program that reads a text file and creates another file that is identical to it.

Answers

Answered by p1998
2
#include<fstream.h>
#include<iostream.h>
#include<process.h>
#include<conio.h>
void main()
{
clrscr();
ifstream file1;
ofstream file2;
char sfile[13],tfile[13];
cout<<"\nEnter Source file name-";
cin>>sfile;
cout<<"\nEnter Target file name-";
cin>>tfile;
file2.open(sfile);
file2<<"\nMy Name is P1998"<<endl;
file2.close();
file1.open(sfile);
file2.open(tfile);
if(!file1)
{
cerr<<" Some Error..";
exit(1);
}
char varch,p=file1.get();
while(!file1.eof())
{
file2.put(p);
varch=file1.get();

if(p==' ' && varch==' ')
{
p=varch;
varch=file1.get();
}
p=varch;

}
cout<<"\ncopied......";
file1.close();
file2.close();
cout<<"\nTarget File Contents....\n";
file1.open(tfile);
while(!file1.eof())
{
file1.get(varch);
cout<<varch;
}
file1.close();
getch();
}
Similar questions