multimap-empty

////////////////////////////////////////
//      2018/05/02 19:30:05
//      multimap-empty

// true if the multimap is empty

#include <iostream>
#include <map>

using namespace std;

int main(){
    typedef multimap<int, int> M;
    typedef M::value_type v_t;
    M m;

    m.insert(v_t(1,100));
    m.insert(v_t(1,200));
    m.insert(v_t(2,300));
    m.insert(v_t(3,400));

    cout << "values of multimap 'm':";
    M::iterator it = m.begin();
    while (it != m.end()){
        cout << it->first << "-" << it->second << endl;
        it++;
    }
    cout << endl;
    cout << "size of multimap = " << m.size() << endl;
    cout << "multimap 'm' is " << (m.empty() ? "" : "not ") << "empty." << endl;

    m.erase(m.begin(),m.end());

    cout << "After m.erase(m.begin(), m.end())" << endl;
    cout << "size of multimap = "<< m.size() << endl;
    cout << "multimap 'm' is " << (m.empty() ? "" : "not ") << "empty." << endl;

    return 0;
}

/*
OUTPUT:
    values of multimap 'm':1-100
    1-200
    2-300
    3-400

    size of multimap = 4
    multimap 'm' is not empty.
    After m.erase(m.begin(), m.end())
    size of multimap = 0
    multimap 'm' is empty.
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12537837.html