1: //adjacent_find1a.cpp
3: #include <iostream>
4: #include <vector>
5: #include <algorithm>
6: using namespace std;
8: int main()
9: {
10: cout << "\nThis program illustrates the use of the STL "
11: "adjacent_find() algorithm\n(default version) to find "
12: "adjacent equal values in a vector of integers.";
13: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
15: int a[] = {1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10};
16: vector<int> v(a, a+12);
17: cout << "\nHere are the values in the vector:\n";
18: for (vector<int>::size_type i=0; i<v.size(); i++)
19: cout << v.at(i) << " ";
20: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
22: vector<int>::iterator p = adjacent_find(v.begin(), v.end());
23: if (p == v.end())
24: cout << "\nThere are no, or no more, matching pairs.";
25: else
26: cout << "\nFirst value of first matching pair is "
27: << *p << ".";
28: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
30: p = adjacent_find(p+1, v.end());
31: if (p == v.end())
32: cout << "\nThere are no, or no more, matching pairs.";
33: else
34: cout << "\nFirst value of next matching pair is "
35: << *p << ".";
36: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
38: p = adjacent_find(p+1, v.end());
39: if (p == v.end())
40: cout << "\nThere are no, or no more, matching pairs.";
41: else
42: cout << "\nFirst value of next matching pair is "
43: << *p << ".";
44: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
46: p = adjacent_find(p+1, v.end());
47: if (p == v.end())
48: cout << "\nThere are no, or no more, matching pairs.";
49: else
50: cout << "\nFirst value of next matching pair is "
51: << *p << ".";
52: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
53: }