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

 1 #include <iostream>
 2 #include <fstream>
 3 using namespace std;
 4 int main()
 5 {
 6  string x, y, z;
 7  cin >> x >> y >> z;
 8  
 9  ifstream file1(x.c_str());
10  ifstream file2(y.c_str());
11  ofstream file3(z.c_str());
12  
13  string a, b;
14  getline(file1,a);
15  getline(file2,b);
16  int aa=a.length();
17  int bb=b.length();
18  cout<<"length of file1:"<<aa<<endl<<"length of file2:"<<bb<<endl; 
19  if(aa>=bb){
20   aa=bb;
21  }
22  bool flag = true;
23     for(int i=0;i<aa;i++){
24      if(a[i]!=b[i]){
25       cout<<"file1:";
26       cout<<a<<endl;
27       cout<<"file2:";
28          cout<<b<<endl;
29    file3 << "Different " << i << endl;
30    cout << "Different " << i << endl;
31    flag = false;
32    break;
33   }
34  }
35  if(flag){
36       cout<<"file1:";
37       cout<<a<<endl;
38       cout<<"file2:";
39       cout<<b<<endl;
40    file3 << "Same " << aa << endl;
41    cout << "Same" << aa << endl;
42  }
43     
44  file1.close();
45  file2.close();
46  file3.close();
47 }

 

转载于:https://www.cnblogs.com/sysu-eeman-yang/p/5987515.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值