Tuesday, 27 May 2014

Merge Files in c++

                             Merge Text Files


#include<conio.h>
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
fstream f1,f2,f3;
char a1[50],a2[50],a3[101];
f1.open("one.txt",ios::out);
if(f1.is_open())
{
cout<<"\n enter the content of file1";
gets(a1);
f1<<a1;
f1.close();
cout<<"\n file written successfully";
}
else cout<<"file can not be opened:";

f2.open("two.txt",ios::out);
if(f2.is_open())
{
cout<<"\n enter the content of file2";
gets(a2);
f2<<a2;
f2.close();
cout<<"\n file written successfully";
}
else cout<<"file can not be opened:";

f1.open("one.txt",ios::in);
f1.read((char *)&a1,sizeof(a1));
f1.close();

f2.open("two.txt",ios::in);
f2.read((char *)&a2,sizeof(a2));
f2.close();

f3.open("three.txt",ios::out);
if(f3.is_open())
{
f3<<a1<<endl<<a2;
f3.close();
cout<<"\n file3 written succesfully:";
}
f3.open("three.txt",ios::in);
f3.read((char *)&a3,sizeof(a3));

f3.close();
puts(a3);

getch();
return 0;

}


  Shashank Chauhan   Naveen Dengani

No comments:

Post a Comment