multimap-find

////////////////////////////////////////
//      2018/05/04 17:04:52
//      multimap-find

// finds a given element
#include <iostream>
#include <map>

using namespace std;

int main(){
    typedef multimap<int, char> M;
    typedef M::value_type v_t;
    char ch = 'A';
    M m;

    for (int i = 0; i < 5; i++){
        m.insert(v_t(i++,ch++));
    }
    m.insert(v_t(4,'F'));

    M::iterator it = m.begin();
    cout << "multimap m:" << endl;

    while (it != m.end()){
        cout << it->first << "-" << it->second << endl;
        it++;
    }

    it = m.find(4);
    if (it != m.end()){
        cout << "element key '4' has value" << it->second << endl;
    }else{
        cout << "element key '4' not found." << endl;
    }

    M::iterator upp = m.upper_bound(4);
    cout << "all elements with key '4'" << endl;
    while (it != upp){
        cout << it->first << "-" << it->second << endl;
        it++;
    }

    return 0;
}


/*
OUTPUT:
    multimap m:
    0-A
    2-B
    4-C
    4-F
    element key '4' has valueC
    all elements with key '4'
    4-C
    4-F
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12537831.html