thespeedracer38

File6

Mar 11th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     char in_file[1024], out_file[1024];
  9.     system("clear");
  10.     cout << "Enter the name of the input file: ";
  11.     cin.getline(in_file, 1024, '\n');
  12.     cout << "Enter the name of the output file: ";
  13.     cin.getline(out_file, 1024, '\n');
  14.     ifstream in(in_file);
  15.     in.seekg(0, ios::end);
  16.     long file_size = in.tellg();
  17.     char *content = new char[file_size];
  18.     in.seekg(0, ios::beg);
  19.     ofstream out(out_file);
  20.     int index = 0;
  21.     // Reading the file and storing it in content
  22.     while(in.get(content[index++])){}
  23.     in.close();
  24.     // Storing the file in reverse
  25.     for(int i = file_size - 1; i >= 0; i--){
  26.         out.put(content[i]);
  27.     }
  28.     out.close();
  29.     delete[] content;
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment