compare 2 files

Could anyone please help me how to compare 2 files containing lines of string? The two files contain similar data except that one contains data with duplicates while the other one contains all unique. I have to make sure if the file having unique data contains all the lines present in the file containing duplicates.

Both files look something like this and I have to compare only the lines which has the sub string CME in it which comes right before the first coma in the string

[code removed]
Last edited on by admin
Hi,

You can compare individual rows away.
to do this, use getline.
Write to the string with getline.
Compare the strings.
in this case, do I not have to compare each row of one file with each row of another and there are over 60000 rows in the file that has duplicate values. Will it not be too slow?
If this isn't some kind of C++ assignment, just use the diff command in UNIX/Linux...
can not think of another idea.
I think ultimately have to be checked every line of this file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
 ifstream ifs1("data1.txt");
 ifstream ifs2("data2.txt");
 ofstream ofs("result.txt");
 string line1;
 string line2;
 while (!ifs2.eof())
 {
 getline(ifs2,line2);
 while (!ifs1.eof()) {
 getline(ifs1,line1);
 if (line1!=line2) {
 ofs << line1;
 ofs << "\n";
 }
else {
 }
}
 }
return 0;
}
Topic archived. No new replies allowed.