-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcont2.cpp
95 lines (74 loc) · 1.69 KB
/
cont2.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
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <set>
using namespace std;
template<typename T>
using Iterator = typename T::iterator;
template<typename C, typename V>
vector<Iterator<C>> find_all(C&c, V v)
{
vector<Iterator<C>> res;
for (auto p = c.begin(); p!=c.end(); ++p) {
if (*p == v) {
res.push_back(p);
}
}
return res;
}
void test()
{
string m{"Mary had a little lamb"};
for (auto p : find_all(m, 'a')) {
if (*p != 'a') {
cerr<<"string bug\n";
}
}
}
int test_iterators()
{
string from, to;
cout << "Enter Input file: ";
cin >> from;
cout << "Enter Output file: ";
cin >> to;
ifstream is{from};
istream_iterator<string> ii{is};
istream_iterator<string> eos{};
ofstream os{to};
ostream_iterator<string> oo{os, "\n"};
vector<string> b {ii, eos};
for (auto p = b.begin(); p != b.end(); ++p) {
cout << *p << endl;
}
sort(b.begin(), b.end());
unique_copy(b.begin(), b.end(), oo);
return !is.eof()|| !os;
}
int test2_iterators()
{
string from, to;
cout << "Enter Input file: ";
cin >> from;
cout << "Enter Output file: ";
cin >> to;
ifstream is{from};
istream_iterator<string> ii{is};
istream_iterator<string> eos{};
ofstream os{to};
ostream_iterator<string> oo{os, "\n"};
set<string> b {ii, eos};
for (auto p = b.begin(); p != b.end(); ++p) {
cout << *p << endl;
}
copy(b.begin(), b.end(), oo);
return !is.eof()|| !os;
}
int main()
{
return test2_iterators();
}