-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemDups.cpp
More file actions
44 lines (36 loc) · 1.18 KB
/
RemDups.cpp
File metadata and controls
44 lines (36 loc) · 1.18 KB
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
#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include <vector>
#include <set>
using namespace std;
int main()
//This routine simply eliminates duplicates from our (unmunched) Latin dictionary by building a <set> of words to swiftly check for novelty.
{
ifstream dictIn;
dictIn.open("latinwords-noVs.txt",ifstream::in);
if (!dictIn.is_open()) {
cerr<<"Error opening latinwords-noVs.txt file!"<<endl;
exit(-1);
}
cout<<"la.aff opened for reading."<<endl;
ofstream dictOut;
dictOut.open("la-novs-nodups.txt",ofstream::out);
if (!dictOut.is_open()) {
cerr<<"Error opening la-novs-nodups.txt file for writing."<<endl;
exit(-1);
}
cout<<"la-novs-nodups.txt opened for writing."<<endl;
set<string> vocab;
string load_a_word;
pair <set<string>::iterator,bool> ret;
while (!dictIn.eof()) {
getline(dictIn,load_a_word);
ret=vocab.insert(load_a_word);
if (ret.second) dictOut<<load_a_word<<endl; //second element of the return value pair == true if insertion added a new item, false if item already in set.
}
dictIn.close();
dictOut.close();
return 0;
}