multimap-size

////////////////////////////////////////
//      2018/05/06 9:29:46
//      multimap-size

// the number of elements in the maltimap
#include <iostream>
#include <map>
#include <iomanip>
#include <string>

using namespace std;

template<class T>
class ID{
private:
    T Id, name;
public:
    ID(T t, T n) :Id(t), name(n){}
    void print(){
        cout.setf(ios::left);
        cout << setw(15) << name << " " << Id << endl;
        cout.unsetf(ios::left);
    }
};

//=======================================
int main(){
    typedef ID<string> Id;
    typedef multimap<int, Id> M;
    typedef M::value_type v_t;

    M m;
    m.insert(v_t(1,Id("000123","Shevchenko")));
    m.insert(v_t(2,Id("000124","Pushkin")));
    m.insert(v_t(3,Id("000125","Shakesperae")));
    // same key
    m.insert(v_t(3,Id("000126","Smith")));

    cout << "size of multimap 'm' = " << m.size() << endl;

    M::iterator it = m.begin();
    while (it != m.end()){
        cout.setf(ios::left);
        cout << setw(3) << it->first;
        it->second.print();
        it++;
    }
    return 0;
}

/*
OUTPUT:
    size of multimap 'm' = 4
    1  Shevchenko      000123
    2  Pushkin         000124
    3  Shakesperae     000125
    3  Smith           000126
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12537818.html