-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWordIterTest.cpp
54 lines (39 loc) · 1.19 KB
/
WordIterTest.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
#include "WordIter.h"
#include <iostream.h>
#include <vector>
#include <algorithm>
using std::string;
using std::vector;
using std::copy;
using std::sort;
using std::for_each;
using std::count;
using std::min_element;
void PrintString(string & str)
{
cout << '\"' << str << '\"' << endl;
}
int main(int argc, char* argv[])
{
string test1 = "This is a test of the word iterator. "
"It should use a word several times for the word count";
// Explicit use.
WordIter wi(test1);
while ( wi != WordIter())
{
cout << '\"' << *wi << '\"' << endl;
++wi;
}
// Using STL algortihms
wi = test1;
for_each(wi, WordIter(), PrintString);
WordIter pMinWord = min_element(wi, WordIter());
PrintString(*pMinWord);
cout << count(wi, WordIter::EOS, string("word")) << endl;
// caching to a vector for better access.
wi = test1;
vector<string> sentence;
copy(wi, WordIter(test1.end()), std::back_inserter(sentence));
for_each(sentence.begin(),sentence.end(), PrintString);
return(0);
}