3/13/2016

C++ Program To Copy Contents Of One File Into Another

Problem:- C++ Program To Copy Contents Of One File Into Another or c++ copy text file to another file or program to copy contents of one file to another in c or c++ program to copy one file to another using command line arguments or c++ copy file to another file or c++ fstream copy file or c++ copy file example or write a c++ program that copies contents of one file to another file or c++ program to merge two files into the third file or c++ program to copy contents of one file into another or c++ copy text file to another file or program to copy contents of one file to another in c or c++ copy file to another file or c++ program to copy one file to another using command line arguments or write a c++ program that copies contents of one file to another file or c++ copy file example

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

Explanation:- So in this problem, we have copied the one file into another file. The program first will ask you to enter the first file name after that ask for entering the second file name than program copied the first file into the second file. We have to enter 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.


Solution:-

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
 //Ghanendra Yadav 
 ifstream fs;
 ofstream ft;
 char ch, fname1[20], fname2[20];
 cout<<"Enter Source File Name With Extension : ";
 gets(fname1);
 fs.open(fname1);
 if(!fs)
 {
  cout<<"Error In Opening Source File..!!";
  getch();
  exit(1);
 }
 cout<<"Enter Destination File Name With Extension : ";
 gets(fname2);
 ft.open(fname2);
 if(!ft)
 {
  cout<<"Error In Opening Target File..!!";
  fs.close();
  getch();
  exit(2);
 }
 while(fs.eof()==0)
 {
  fs>>ch;
  ft<<ch;
 }
 cout<<"File Copied Successfully..!!";
 fs.close();
 ft.close();
 getch();
}

Output:-

C++ Program To Copy Contents Of One File Into Another


Input:- FILE 1 Source File

C++ Program To Copy Contents Of One File Into Another


Input:- FILE 2 Destination File

C++ Program To Copy Contents Of One File Into Another



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. C++ Program For Count A Character In File Using File

6. C++ Program For Reading A Number From File And Sum Of No. Line By Line Using File

7. C++ Program For Store Employee Information And Display Using Structure

8. C Program For Find A Grade Of Given Marks Using Switch Case

9. C Program For HEAP Sort In Ascending Order Also Show Complexity

10. C++ Program For Selection Sort Using Function

No comments:

Post a Comment