1: //multiset02.cpp
3: #include <iostream>
4: #include <set>
5: #include <string>
6: using namespace std;
8: int main()
9: {
10: cout << "\nThis program illustrates finding and processing all copies "
11: "of a\nparticular value in a multiset.";
12: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
14: cout << "\nHere are the values in the mulitset: ";
15: int a[] = {1, 1, 2, 3, 4, 4, 4, 5};
16: multiset<int> ms(a, a+8);
17: multiset<int>::iterator p = ms.begin();
18: while (p != ms.end()) cout << *p++ << " ";
19: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
21: multiset<int>::iterator lower, upper;
22: lower = ms.lower_bound(4);
23: cout << "\nLower bound of 4 ..................... " << *lower;
24: --lower;
25: cout << "\nValue previous to lower bound of 4 ... " << *lower;
26: upper = ms.upper_bound(4);
27: cout << "\nUpper bound of 4 ..................... " << *upper;
28: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
30: cout << "\nFinally, we display all copies of 4 from the multiset: ";
31: pair<multiset<int>::iterator, multiset<int>::iterator> upper_lower;
32: upper_lower = ms.equal_range(4);
33: p = upper_lower.first;
34: while (p!= upper_lower.second) cout << *p++ << " ";
35: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
36: }