⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_13_4.cpp

📁 data+structures+using+c的源码
💻 CPP
字号:
#include <iostream>
#include <map>
#include <utility>
#include <string>
#include <iterator>

using namespace std;

int main()
{
    map<int, int> intMap;                            //Line 1
    map<int, int>::iterator mapItr;                  //Line 2

    intMap.insert(make_pair(1, 16));                 //Line 3
    intMap.insert(make_pair(2, 8));                  //Line 4
    intMap.insert(make_pair(4, 20));                 //Line 5
    intMap.insert(make_pair(3, 3));                  //Line 6
    intMap.insert(make_pair(1, 23));                 //Line 7
    intMap.insert(make_pair(20, 18));                //Line 8
    intMap.insert(make_pair(8, 28));                 //Line 9
    intMap.insert(make_pair(15, 60));                //Line 10
    intMap.insert(make_pair(6, 43));                 //Line 11
    intMap.insert(pair<int, int>(12, 16));           //Line 12

    cout<<"Line 13: The elements of intMap:"<<endl;  //Line 13
    for(mapItr = intMap.begin(); mapItr != intMap.end();
                                 mapItr++)           //Line 14
        cout<<mapItr->first<<"\t"<<mapItr->second
            <<endl;                                  //Line 15
    cout<<endl;                                      //Line 16

    intMap.erase(12);                                //Line 17

    mapItr = intMap.begin();                         //Line 18
    ++mapItr;                                        //Line 19
    ++mapItr;                                        //Line 20
    intMap.erase(mapItr);                            //Line 21

    cout<<"Line 22: After deleting, the elements of intMap:"
        <<endl;                                      //Line 22
    for(mapItr = intMap.begin(); mapItr != intMap.end();
                                 mapItr++)           //Line 23
        cout<<mapItr->first<<"\t"<<mapItr->second
            <<endl;                                  //Line 24
    cout<<endl;                                      //Line 25

    multimap<string, string> namesMultiMap;          //Line 26
    multimap<string, string>::iterator nameItr;      //Line 27

    namesMultiMap.insert(make_pair("A1", "Donny"));  //Line 28
    namesMultiMap.insert(make_pair("B1", "Zippy"));  //Line 29
    namesMultiMap.insert(make_pair("K1", "Goofy"));  //Line 30
    namesMultiMap.insert(make_pair("A2", "Hungry")); //Line 31
    namesMultiMap.insert(make_pair("D1", "Goofy"));  //Line 32
    namesMultiMap.insert(make_pair("A1", "Dumpy"));  //Line 33

    cout<<"Line 34: namesMultiMap: "<<endl;          //Line 34
    for(nameItr = namesMultiMap.begin(); 
                nameItr != namesMultiMap.end();
                nameItr++)                           //Line 35
        cout<<nameItr->first<<"\t"<<nameItr->second
            <<endl;                                  //Line 36
    cout<<endl;                                      //Line 37

    return 0;                                        //Line 38
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -