STL Map使用

/*
description:
STL  map使用

author:Jason
date:20160521
*/
#include<stdio.h>
#include <map>
#include<iostream>
using namespace std;


int main()
{
    map<char,int>  mymap;
    int data[]={31,-41,59,26,-53,58,97,-93,-23,84,33,22};
    int len=sizeof(data)/sizeof(data[0]);
    cout<<"len="<<len<<endl;
    for (int i=0;i<len;i++)
    {
        mymap.insert(pair<char,int>(char('a'+i),data[i]));
    }
    map<char,int>::iterator it;
    for (it=mymap.begin(); it!=mymap.end(); ++it)
    {
        cout << it->first  <<" -> "<<it->second<<endl;
    }


    cout<<endl;
    cout<<"max_size:"<<mymap.max_size()<<endl;
    return 0;

}

insert Insert elements (public member function )
erase
Erase elements (public member function )
swap
Swap content (public member function )
clear
Clear content (public member function )
emplace
Construct and insert element (public member function )
emplace_hint
Construct and insert element with hint (public member function )

發佈了118 篇原創文章 · 獲贊 16 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章