C++ Program to read from a text file and than write in another text file

#include<fstream.h>

void main()
{

ofstream fout(“sare1.txt”); //create a file to write
ifstream fin(“sare1.txt”);
fout<<“Hello….!!”;
fout.close();                            //closing the file

fout.open(“sare2.txt”); //create file to write
char ch;
while(fin) //loop wiill run till end of file
{
fin>>ch;       //reading data from file
fout<<ch;       //writing data to file
}
fin.close();
fout.close();
}
/*you can see the file sare2 in your BIN
folder containg data same as of file sare1*/

Leave a Comment

Your email address will not be published. Required fields are marked *