-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsimple_dictionary_v2.cpp
More file actions
29 lines (24 loc) · 960 Bytes
/
simple_dictionary_v2.cpp
File metadata and controls
29 lines (24 loc) · 960 Bytes
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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
// "quick and dirty" dictionary: read words from a text file, sort and remove duplicates,
// then write to another file
int main(int argc, char* argv[]) {
if (argc < 3) {
cout << "Usage: " << argv[0] << " input_file output_file\n";
return 0;
}
ifstream is(argv[1]); // open input stream
ofstream os(argv[2]); // open output stream
istream_iterator<string> ii(is); // make input iterator for stream
istream_iterator<string> eos; // input sentinel
ostream_iterator<string> oo(os, "\n"); // make output iterator for stream
vector<string> b(ii, eos); // b is a vector initialized from input
sort(b.begin(), b.end()); // sort the buffer
unique_copy(b.begin(), b.end(), oo); // copy buffer to output
return 0;
}