假設A,B兩個文件,A文件中100行字符,B文件中200行字符。輸出B中與A中行內容不同的行。
// find different lines from two text
#include "iostream"
#include "fstream"
#include "string"
#include "vector"
int main()
{
using namespace std;
string filename1,filename2;
cout << "Enter the first file name:";
cin >> filename1;
cout << "Enter the second file name:";
cin >> filename2;
ifstream fin1(filename1.c_str());
ifstream fin2(filename2.c_str());
string temp;
vector<string> a;
vector<string> b;
while(getline(fin1,temp))
{
a.push_back(temp);
}
while(getline(fin2,temp))
{
b.push_back(temp);
}
fin1.close();
fin2.close();
int sum = 0;
for(int t = 0; t < b.size();t++)
{
int count = 0;
for(int s = 0;s < a.size() ;s++)
{
if(b[t].compare(a[s])==0)
break;
else
count++;
}
if(count >= a.size())
{
cout << b[t] << endl;
sum++;
}
}
cout << "sum = " << sum << endl;
return 0;
}