dw php网站开发书籍云盘,广告传媒公司名字大全最新,青岛市做网站,公司可以做多个网站吗转载#xff1a;http://blog.csdn.net/stpeace/article/details/44984639 我个人感觉哈#xff0c; map的应用场景比multimap更多#xff0c; 不过#xff0c; 我们还是来学一下multimap。 我们知道#xff0c; multimap中#xff0c; 一个关键字可能对应多个不同的值http://blog.csdn.net/stpeace/article/details/44984639 我个人感觉哈 map的应用场景比multimap更多 不过 我们还是来学一下multimap。 我们知道 multimap中 一个关键字可能对应多个不同的值 怎么获取呢我们来看程序 接招介绍三种方法 结果为 [cpp] view plaincopy #pragma warning(disable : 4786) #include map #include string #include iostream using namespace std; int main() { multimapint, string mp; mp.insert(pairint, string(3, hehe)); mp.insert(pairint, string(4, haha)); mp.insert(pairint, string(2, error)); mp.insert(pairint, string(3, good)); mp.insert(pairint, string(3, ok)); mp.insert(pairint, string(3, hehe)); multimapint, string::iterator it; for(it mp.begin(); it ! mp.end(); it) { cout it-first ---; cout it-second endl; } // 方法一 int n mp.count(3); // 3的个数 cout n endl; int i 0; it mp.find(3); // 第一个3的位置 for(i 0; i n; i) { cout it-first ---; cout it-second endl; it; // 所有的3必然是相连的 } cout --------------------------- endl; // 方法二 for(it mp.lower_bound(3); it ! mp.upper_bound(3); it) { cout it-first ---; cout it-second endl; } cout --------------------------- endl; // 方法三 pairmultimapint, string::iterator, multimapint, string::iterator pos; for(pos mp.equal_range(3); pos.first ! pos.second; pos.first) { cout pos.first-first ---; cout pos.first-second endl; } return 0; } 结果为 2---error 3---hehe 3---good 3---ok 3---hehe 4---haha 4 3---hehe 3---good 3---ok 3---hehe --------------------------- 3---hehe 3---good 3---ok 3---hehe --------------------------- 3---hehe 3---good 3---ok 3---hehe Press any key to continue