thespeedracer38

File5a

Mar 11th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 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_filename[1024], out_filename[1024];
  9.     system("clear");
  10.     cout << "Enter the name of the input file: ";
  11.     cin.getline(in_filename, 1024, '\n');
  12.     cout << "Enter the name of the output file: ";
  13.     cin.getline(out_filename, 1024, '\n');
  14.  
  15.     ifstream in(in_filename, ios::in);
  16.     fstream out(out_filename, ios::in | ios::out | ios::trunc);
  17.    
  18.     if(!in){
  19.         cout << "Could not open input file" << endl;
  20.         return 1;
  21.     }
  22.     else{
  23.         char ch;
  24.         while(in.get(ch)){
  25.             if(ch >= 'a' && ch <= 'z'){
  26.                 out.put(ch - 32);  
  27.             }
  28.             else{
  29.                 out.put(ch);
  30.             }
  31.         }
  32.         // Displaying the output file
  33.         cout << "The contents of the output file is\n";
  34.         out.seekp(0, ios::beg);
  35.         while(out.get(ch)){
  36.             cout << ch;
  37.         }
  38.     }
  39.     in.close();
  40.     out.close();
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment