• map-empty


    ////////////////////////////////////////
    //      2018/05/01 14:22:47
    //      map-empty
    
    // true if the map is empty
    #include <iostream>
    #include <map>
    
    using namespace std;
    
    int main(){
        typedef map<int, int> M;
        M m;
    
        m[1] = 100;
        m[3] = 200;
        m[5] = 500;
    
        cout << "values of map 'm':";
        M::iterator it = m.begin();
        while (it != m.end()){
            cout << it->second << " ";
            it++;
        }
        cout << endl;
    
        cout << "size of map = " << m.size() << endl;
        cout << "map '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 map = " << m.size() << endl;
        cout << "map 'm' is " << (m.empty() ? "" : "not ") << "empty." << endl;
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        values of map 'm':100 200 500
        size of map = 3
        map 'm' is not empty.
        After m.erase(m.begin(), m.end())
        size of map = 0
        map 'm' is empty.
    */
  • 相关阅读:
    gvim : invalid input string
    端口
    Sequence Overview
    vi的使用
    Ubuntu安装CodeBlocks相关问题总结
    中断
    Ubuntu Software Repository
    UVA 12299 RMQ with Shifts
    UVA 12293 Box Game
    POJ 3468 A Simple Problem with Integers (1)
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537860.html
Copyright © 2020-2023  润新知