Copy One File to another File

// Copy one file to another.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include < iostream >
#include < conio.h >
#include < iomanip >
 #include < fstream >
using namespace std;
   void main( )
   {
     ofstream outfile;
     ifstream infile;
     char fname1[10],fname2[20];
     char ch,uch;
     cout<<"Enter a file name to be copied ";
     cin>> fname1;
     cout<<"Enter new file name";
     cin>>fname2;
     infile.open(fname1);
     if( infile.fail( ) )
     {
       cerr<< " No such a file Exit";
       exit(1);
     }
     outfile.open( fname2);
       if(outfile.fail( ))
       {
         cerr<<"Unable to create a file";
         exit(1);
       }
       while( !infile.eof( ) )
       {
         ch = (char) infile.get( );
         uch = toupper(ch);
         outfile.put(uch);
         }
     infile.close( );
     outfile.close( );
        system("pause");

   }
Share on Google Plus