1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <iostream> #include<fstream> #include <utility> #include <set> #include <map> #include <string> using std::pair; using std::map; using std::set; using std::multimap; using std::multiset; using std::string; using std::cin; using std::cout; using std::endl;
int main() { set<string> set1; set1.insert("A"); set<string> set2; set2.insert(set1.begin(), set1.end());
set<string>::iterator it = set2.find("A"); set2.count("A");
multimap<string, string> mapping; mapping.insert(std::make_pair("A", "B")); mapping.insert(std::make_pair("A", "C")); string search_item("A"); multimap<string, string>::size_type enties = mapping.count(search_item); multimap<string, string>::iterator it2 = mapping.find(search_item); for (multimap<string, string>::size_type i = 0; i != enties; ++i, ++it2) cout << it2->first << ":" << it2->second << endl;
multimap<string, string>::iterator beg = mapping.lower_bound(search_item), end = mapping.upper_bound(search_item); while (beg != end) { cout << beg->first << ":" << beg->second << endl; ++beg; } typedef multimap<string, string>::iterator map_it; pair<map_it, map_it> pos = mapping.equal_range(search_item); while (pos.first != pos.second) { cout << pos.first->first << ":" << pos.first->second << endl; ++pos.first; } multimap<string, string>::size_type cnt = mapping.erase(search_item); cout << "remove :" << cnt << endl;
return 0; }
|