• 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.
    */ 
  • 相关阅读:
    004 使用文本编辑器
    003 第一个Python程序
    002 Python解释器
    001 安装Python
    000 Python教程
    001 Java环境变量配置
    002 基础语法1
    003 基础语法2
    dede首页调用会员积分和头像代码
    DEDE 会员调用方法
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537838.html
Copyright © 2020-2023  润新知