thespeedracer38

File 1

Feb 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     char file1[20], file2[20], ch;
  8.     long i, n;
  9.     system("cls");
  10.    
  11.     // Taking the name of the file as input
  12.    
  13.     cout << "Enter the input file name: ";
  14.     cin >> file1;
  15.     cout << "Enter the output file name: ";
  16.     cin >> file2;
  17.    
  18.     ifstream fp1;
  19.     ofstream fp2;
  20.    
  21.     // Opening the file
  22.     fp1.open(file1, ios::binary);
  23.     fp2.open(file2, ios::binary);
  24.    
  25.     // Moving the file object to the end of the file
  26.     fp1.seekg(0, ios::end);
  27.    
  28.     // To get the last byte position
  29.     n = fp1.tellg();
  30.    
  31.     // Moving file object to the begining of the
  32.     // file
  33.     fp1.seekg(0, ios::beg);
  34.    
  35.     // To copy data from the input file to the
  36.     // output file
  37.     for(i = 1; i <=n ; i++){
  38.         ch = fp1.get();
  39.         fp2.put(ch);
  40.     }
  41.    
  42.     // Closing the files
  43.     fp1.close();
  44.     fp2.close();
  45.    
  46.     // Displaying the size of the file in bytes
  47.     cout    << "\nFile copy is over, Number of bytes copied = "
  48.             << n << endl;
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment