| 1 |
#include <iostream> |
| 2 |
#include <set> |
| 3 |
|
| 4 |
using namespace std; |
| 5 |
|
| 6 |
int main() |
| 7 |
{ |
| 8 |
string |
| 9 |
sa[] = |
| 10 |
{ |
| 11 |
"alpha", |
| 12 |
"echo", |
| 13 |
"hotel", |
| 14 |
"mike", |
| 15 |
"romeo" |
| 16 |
}; |
| 17 |
|
| 18 |
multiset<string> |
| 19 |
object(&sa[0], &sa[5]); |
| 20 |
|
| 21 |
object.insert("echo"); |
| 22 |
object.insert("echo"); |
| 23 |
|
| 24 |
multiset<string>::iterator |
| 25 |
it = object.find("echo"); |
| 26 |
|
| 27 |
for (; it != object.end(); ++it) |
| 28 |
cout << *it << " "; |
| 29 |
cout << '\n'; |
| 30 |
|
| 31 |
cout << "Multiset::equal_range(\"ech\")\n"; |
| 32 |
pair |
| 33 |
< |
| 34 |
multiset<string>::iterator, |
| 35 |
multiset<string>::iterator |
| 36 |
> |
| 37 |
itpair = object.equal_range("ech"); |
| 38 |
|
| 39 |
if (itpair.first != object.end()) |
| 40 |
cout << "lower_bound() points at " << *itpair.first << '\n'; |
| 41 |
for (; itpair.first != itpair.second; ++itpair.first) |
| 42 |
cout << *itpair.first << " "; |
| 43 |
|
| 44 |
cout << '\n' << |
| 45 |
object.count("ech") << " occurrences of 'ech'" << '\n'; |
| 46 |
|
| 47 |
cout << "Multiset::equal_range(\"echo\")\n"; |
| 48 |
itpair = object.equal_range("echo"); |
| 49 |
|
| 50 |
for (; itpair.first != itpair.second; ++itpair.first) |
| 51 |
cout << *itpair.first << " "; |
| 52 |
|
| 53 |
cout << '\n' << |
| 54 |
object.count("echo") << " occurrences of 'echo'" << '\n'; |
| 55 |
|
| 56 |
cout << "Multiset::equal_range(\"echoo\")\n"; |
| 57 |
itpair = object.equal_range("echoo"); |
| 58 |
|
| 59 |
for (; itpair.first != itpair.second; ++itpair.first) |
| 60 |
cout << *itpair.first << " "; |
| 61 |
|
| 62 |
cout << '\n' << |
| 63 |
object.count("echoo") << " occurrences of 'echoo'" << '\n'; |
| 64 |
} |
| 65 |
/* |
| 66 |
Generated output: |
| 67 |
|
| 68 |
echo echo echo hotel mike romeo |
| 69 |
Multiset::equal_range("ech") |
| 70 |
lower_bound() points at echo |
| 71 |
|
| 72 |
0 occurrences of 'ech' |
| 73 |
Multiset::equal_range("echo") |
| 74 |
echo echo echo |
| 75 |
3 occurrences of 'echo' |
| 76 |
Multiset::equal_range("echoo") |
| 77 |
|
| 78 |
0 occurrences of 'echoo' |
| 79 |
*/ |