C++ STL :unordered_multimap

1、代码

#include<iostream>
#include<unordered_map>
using namespace std;

int main() {
    unordered_multimap<int, int> myUnorderedMultiMap = { {2, 10},{1, 20},{3,30} };
    //正向迭代器测试
    cout << "正向迭代器遍历容器:";
    for (auto it = myUnorderedMultiMap.begin(); it != myUnorderedMultiMap.end(); ++it) {
        cout << it->first << " -> " << it->second << ", ";
    }
    cout << endl;
    //正向常迭代器测试
    cout << "正向常迭代器遍历容器:";
    for (auto cit = myUnorderedMultiMap.cbegin(); cit != myUnorderedMultiMap.cend(); ++cit) {
        cout << cit->first << " -> " << cit->second << ", ";
    }
    cout << endl;
    return 0;
}

参考:https://blog.csdn.net/qq_41855420/article/details/89792468

posted @ 2022-10-08 21:31  朱小勇  阅读(66)  评论(0编辑  收藏  举报