Advertisement
zemf4you

Untitled

Jul 13th, 2021
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iterator>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[]) {
  8.     string firstPath;
  9.     string secondPath;
  10.     string outputPath;
  11.     if (argc == 4) {
  12.         firstPath = argv[1];
  13.         secondPath = argv[2];
  14.         outputPath = argv[3];
  15.     } else {
  16.         cout << "Enter first file path" << endl;
  17.         cin >> firstPath;
  18.         cout << "Enter second file path" << endl;
  19.         cin >> secondPath;
  20.         cout << "Enter output file path" << endl;
  21.         cin >> outputPath;
  22.     }
  23.     ifstream firstFile(firstPath, ios::in);
  24.     string first{istreambuf_iterator<char>(firstFile), istreambuf_iterator<char>()};
  25.    
  26.     ifstream secondFile(secondPath, ios::in);
  27.     string second{istreambuf_iterator<char>(secondFile), istreambuf_iterator<char>()};
  28.    
  29.     ofstream output;
  30.     output.open(outputPath, ios::out | ios::app);
  31.    
  32.     for (int i = 0; i < min(first.length(), second.length()); i++)
  33.         if (first[i] != second[i])
  34.             output << i << ": " << first[i] << " != " << second[i] << endl;
  35.    
  36.     int diff = first.length() - second.length();
  37.     if (diff == 0)
  38.         return 0;
  39.     else if (diff < 0)
  40.         diff = -diff;
  41.    
  42.     output << "length diff is " << diff << endl;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement