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
| void main(){ multimap<int, string> map1;
map1.insert(pair<int, string>(1,"11")); map1.insert(pair<int, string>(1, "12")); map1.insert(pair<int, string>(1, "13"));
map1.insert(pair<int, string>(3, "31")); map1.insert(pair<int, string>(3, "32")); map1.insert(pair<int, string>(3, "33"));
map1.insert(pair<int, string>(2, "21")); map1.insert(pair<int, string>(2, "23")); map1.insert(pair<int, string>(2, "22"));
for (map<int, string>::iterator it = map1.begin(); it != map1.end(); it++) { cout << it->first << " " << (it->second).c_str() << endl; } cout << " 遍历结束" << endl;
multimap<int, string>::iterator find_it = map1.find(3); while (find_it != map1.end()){ cout << find_it->first << " " << (find_it->second).c_str() << endl; find_it++; if (find_it == map1.end() || find_it -> first != 3){ break; } }
getchar(); }
|