-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathmerge_data.cpp
84 lines (52 loc) · 1.64 KB
/
merge_data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
void find(string word) {
string line;
int count = 0;
ifstream myfile ("/Users/swe_mini/Desktop/a.txt");
if (myfile.is_open())
{
while(getline(myfile, line)){
if(line.find(word) != string::npos){
//cout << word << endl;
count ++;
}
}
cout <<"its -- > "<<count << endl;
myfile.close();
}
else cout << "Unable to open file";
}
int main () {
string line;
//string word = "elder High High School Wife relative Female gain relax United-States >50K";
int count = 0;
typedef map<string, int> line_record;
line_record lines;
int line_number = 1;
ifstream mergeFile ("/Users/swe_mini/Desktop/merge.txt");
ifstream myfile ("/Users/swe_mini/Desktop/a.txt");
if (mergeFile.is_open())
{
while ( getline (mergeFile,line) )
{
line_record::iterator existing = lines.find(line);
if(existing != lines.end())
{
existing->second = (-1);
} else
{
lines.insert(make_pair(line,line_number));
++line_number;
find(line);
count++;
}
}
mergeFile.close();
}
else cout << "Unable to open file";
return 0;
}