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: vector<int> v{1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10}; //since C++11 16: cout << "\nHere are the values in the vector:\n"; 17: for (int i : v) cout << i << " "; //since C++11 18: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 20: auto p = adjacent_find(v.begin(), v.end()); //since C++11 21: if (p == v.end()) 22: cout << "\nThere are no, or no more, matching pairs."; 23: else 24: cout << "\nFirst value of first matching pair is " << *p << "."; 25: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 27: p = adjacent_find(p+1, v.end()); 28: if (p == v.end()) 29: cout << "\nThere are no, or no more, matching pairs."; 30: else 31: cout << "\nFirst value of next matching pair is " << *p << "."; 32: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 34: p = adjacent_find(p+1, v.end()); 35: if (p == v.end()) 36: cout << "\nThere are no, or no more, matching pairs."; 37: else 38: cout << "\nFirst value of next matching pair is " << *p << "."; 39: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 41: p = adjacent_find(p+1, v.end()); 42: if (p == v.end()) 43: cout << "\nThere are no, or no more, matching pairs."; 44: else 45: cout << "\nFirst value of next matching pair is " << *p << "."; 46: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 47: }