homework 11 2016 5 13 读入文件做输入

时间:2023-03-09 15:29:12
homework 11 2016 5 13 读入文件做输入

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
 string x, y, z;
 cin >> x >> y >> z;
 
 ifstream file1(x.c_str());
 ifstream file2(y.c_str());
 ofstream file3(z.c_str());
 
 string a, b;
 getline(file1,a);
 getline(file2,b);
 int aa=a.length();
 int bb=b.length();
 cout<<"length of file1:"<<aa<<endl<<"length of file2:"<<bb<<endl;
 if(aa>=bb){
  aa=bb;
 }
 bool flag = true;
    for(int i=0;i<aa;i++){
     if(a[i]!=b[i]){
      cout<<"file1:";
      cout<<a<<endl;
      cout<<"file2:";
         cout<<b<<endl;
   file3 << "Different " << i << endl;
   cout << "Different " << i << endl;
   flag = false;
   break;
  }
 }
 if(flag){
      cout<<"file1:";
      cout<<a<<endl;
      cout<<"file2:";
      cout<<b<<endl;
   file3 << "Same " << aa << endl;
   cout << "Same" << aa << endl;
 }
   
 file1.close();
 file2.close();
 file3.close();
}