Sunday, 13 March 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

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