| 1 |
#include <iostream> |
| 2 |
#include <map> |
| 3 |
using namespace std; |
| 4 |
|
| 5 |
int main() |
| 6 |
{ |
| 7 |
pair<string, int> pa[] = |
| 8 |
{ |
| 9 |
pair<string,int>("alpha", 1), |
| 10 |
pair<string,int>("bravo", 2), |
| 11 |
pair<string,int>("charlie", 3), |
| 12 |
pair<string,int>("bravo", 6), // unordered `bravo' values |
| 13 |
pair<string,int>("delta", 5), |
| 14 |
pair<string,int>("bravo", 4), |
| 15 |
}; |
| 16 |
multimap<string, int> object(&pa[0], &pa[6]); |
| 17 |
|
| 18 |
using msiIterator = multimap<string, int>::iterator; |
| 19 |
|
| 20 |
msiIterator it = object.lower_bound("brava"); |
| 21 |
|
| 22 |
cout << "Lower bound for `brava': " << |
| 23 |
it->first << ", " << it->second << '\n'; |
| 24 |
|
| 25 |
it = object.upper_bound("bravu"); |
| 26 |
|
| 27 |
cout << "Upper bound for `bravu': " << |
| 28 |
it->first << ", " << it->second << '\n'; |
| 29 |
|
| 30 |
pair<msiIterator, msiIterator> |
| 31 |
itPair = object.equal_range("bravo"); |
| 32 |
|
| 33 |
cout << "Equal range for `bravo':\n"; |
| 34 |
for (it = itPair.first; it != itPair.second; ++it) |
| 35 |
cout << it->first << ", " << it->second << '\n'; |
| 36 |
cout << "Upper bound: " << it->first << ", " << it->second << '\n'; |
| 37 |
|
| 38 |
cout << "Equal range for `brav':\n"; |
| 39 |
itPair = object.equal_range("brav"); |
| 40 |
for (it = itPair.first; it != itPair.second; ++it) |
| 41 |
cout << it->first << ", " << it->second << '\n'; |
| 42 |
cout << "Upper bound: " << it->first << ", " << it->second << '\n'; |
| 43 |
} |
| 44 |
/* |
| 45 |
Generated output: |
| 46 |
|
| 47 |
Lower bound for `brava': bravo, 2 |
| 48 |
Upper bound for `bravu': charlie, 3 |
| 49 |
Equal range for `bravo': |
| 50 |
bravo, 2 |
| 51 |
bravo, 6 |
| 52 |
bravo, 4 |
| 53 |
Upper bound: charlie, 3 |
| 54 |
Equal range for `brav': |
| 55 |
Upper bound: bravo, 2 |
| 56 |
*/ |