thespeedracer38

File 3

Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv) {
  7.     system("cls");
  8.     if(argc >= 3){
  9.         const char *output_file = argv[argc - 1];
  10.        
  11.         ofstream o_fp;
  12.         ifstream i_fp;
  13.         int size;
  14.         int total_size = 0;
  15.        
  16.         o_fp.open(output_file, ios::binary);
  17.        
  18.         for(int i = 1; i < argc - 1; i++){
  19.             i_fp.open(argv[i], ios::binary);
  20.             i_fp.seekg(0, ios::end);
  21.             size = i_fp.tellg();
  22.             i_fp.seekg(0, ios::beg);
  23.             total_size += size;
  24.             for(int j = 1; j <= size; j++){
  25.                 o_fp.put(i_fp.get());
  26.             }
  27.             i_fp.close();
  28.         }
  29.        
  30.         cout << "Total Bytes copied = " << total_size << endl;
  31.         cout << "Output file: " << output_file << " created successfuly!" << endl;
  32.         o_fp.close();
  33.         return 0;
  34.     }
  35.     else {
  36.         cout << "In-sufficient number of arguments" << endl;
  37.         cout << "USAGE: File3.exe in_file1 [in_file2 ... ] out_file" << endl;
  38.         return 1;
  39.     }
  40. }
Add Comment
Please, Sign In to add comment