Assuming input file as abc.txt with contents "World" and output file named as xyz.txt with contents "Hello" have been already created.
#include <iostream.h>
#include<fstream.h>
int main()
{
fstream f;
ifstream fin;
fin.open("abc.txt",ios::in);
ofstream fout;
fout.open("xyz.txt", ios::app);
if (!fin)
{
cout<< "file not found";
}
else
{
fout<<fin.rdbuf();
}
char ch;
f.seekg(0);
while (f)
{
f.get(ch);
cout<< ch;
}
f.close();
return 0;
}
Output:
Hello World