Sunday, 13 March 2016

C++ Program to Merge Two Files Into Third File Using File Handling

Problem:- C++ Program to Merge Two Files or C Program to merge contents of two files into a third file or Write a C++ Program to Merge Two Files into a Single file or C++ program append the two text files or Merging 2 text files into a 3rd text file in C++ or merging two files into one in c++ and display it contents or Merging Two Files Into One or C program to merge two files or C Program to Merge Two Files Concatenate Lines From Two Text Files Into Output File C program to merge alternate lines from two files or C Program to Append the Content of File at the end of Another.

Check This- Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.

Explanation:- So in this problem, we have to Merge the two file into an another new file. The program first will ask you to enter the first file name after that ask for entering the second file name than program merge the first file and the second file. We have to enter the both file name with extension cause file always have extension or folder not this is useful when you want to merge two files or in other words, we can say that merge two file. This is not copying one file into the another file in this we have to merge two separate file file1 and file2 into file3 or we can say that we are copying the file1 and file2 in the third file file3.

Also check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.



Tip:- Before copy the solution I recommended please read this full article, this will help you to build your own logic. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe for our new and latest post related to programming this will help you update all about new post this Article.

Solution:-

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
 //Ghanendra Yadav
 ifstream ifiles1, ifiles2;
 ofstream ifilet;
 char ch, fname1[20], fname2[20], fname3[30];
 cout<<"Enter first file name (with extension like file1.txt) : ";
 gets(fname1);
 cout<<"Enter second file name (with extension like file2.txt) : ";
 gets(fname2);
 cout<<"Enter Third File name of file : ";
 gets(fname3);
 ifiles1.open(fname1);
 ifiles2.open(fname2);
 if(ifiles1==NULL || ifiles2==NULL)
 {
  perror("Error Message ");
  cout<<"Press any key to exit...\n";
  getch();
  exit(EXIT_FAILURE);
 }
 ifilet.open(fname3);
 if(!ifilet)
 {
  perror("Error Message ");
  cout<<"Press any key to exit...\n";
  getch();
  exit(EXIT_FAILURE);
 }
 while(ifiles1.eof()==0)
 {
  ifiles1>>ch;
  ifilet<<ch;
 }
 while(ifiles2.eof()==0)
 {
  ifiles2>>ch;
  ifilet<<ch;
 }
 cout<<"The two files were merged into "<<fname3<<" file successfully..!!";
 ifiles1.close();
 ifiles2.close();
 ifilet.close();
 getch();
}

Output:-

C++ Program to Merge Two Files Into Third File Using File Handling


Input:- FILE 1

C++ Program to Merge Two Files Into Third File Using File Handling


Input:- FILE 2

C++ Program to Merge Two Files Into Third File Using File Handling


FINAL OUTPUT:- AFTER MERGING BOTH ABOVE FILE

C++ Program to Merge Two Files Into Third File Using File Handling


You May Like This:-

1. Hacker Rank Solution for 30 Days of Code

2. Hacker Rank solution for Attribute Parser

3. Java Program For Find The Gross Salary Of An Employee

4. Hacker Rank Solution For Conditional Statements

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. C++ Program For Calculate Percentage Of 5 Subjects

8. Hacker Rank Solution For Strings

9. Hacker Rank Solution For Conditional Statements

10. Hacker Rank solution for 30 Days Of Code



Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment