construct map && multimap

作者在 2008-08-17 14:30:51 发布以下内容
//map's constructor,and the multimap's constructor is as some as the map's

#include<iostream>
#include<map>
#include<iterator>
using namespace std;
int main(void)
{
   
typedef pair<int,int> Int_Pair;
    map<int,int>::iterator Iter;
    map<int,int> map1;   //empty map
   
map<int,int,less<int> > map2;    //empty map but have predication 'less'
   
map2.insert(Int_Pair(1,10)), map2.insert(Int_Pair(2,20));
    map<int,int,greater<int> > map3;
    map3.insert(Int_Pair(1,10)), map3.insert(Int_Pair(2,20));
    map<int,int>::allocator_type map2_Alloc;
    map<int,int> map4(less<int>(),map2_Alloc);  //利用map2的内存分配器创建一个map变量map4
   
map4.insert(Int_Pair(3,30));
    map<int,int> map5(map2);    //copy
   
map<int,int>::const_iterator map2_bcIter,map2_ecIter;
    map2_bcIter = map2.begin(),map2_ecIter = map2.begin();
    map2_ecIter++ ,map2_ecIter++;
    map<int,int> map6(map2_bcIter,map2_ecIter);
    map<int,int>::allocator_type map3_Alloc;
    map3_Alloc = map3.get_allocator();
    map<int,int> map7(map5.begin(),++map5.begin(),less<int>(),map3_Alloc);
    cout<<"map2--map7,take one line for each map."<<endl;
    for (Iter = map2.begin(); Iter != map2.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    for (Iter = map3.begin(); Iter != map3.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    for (Iter = map4.begin(); Iter != map4.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    for (Iter = map5.begin(); Iter != map5.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    for (Iter = map6.begin(); Iter != map6.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    for (Iter = map7.begin(); Iter != map7.end();Iter++) cout<<Iter->second<<" ";
    cout<<endl;
    return 0;
}
STL | 阅读 4476 次
文章评论,共0条
游客请输入验证码
浏览56291次
最新评论