#include <map> html
#include <iostream> ios
using namespace std; spa
typedef map<int,char> icMap; //默認htm
typedef map<int,char>::iterator It; blog
typedef struct list排序
{it
bool operator()(const int a,const int b) constio
{stream
return a>b;map
}
};
typedef map<int,char,list> icMapCmp;//加了排序
typedef map<int,char,list>::iterator It1;
int main(void)
{
icMap m;
m.insert(make_pair(1,'1'));
m.insert(make_pair(5,'3'));
m.insert(make_pair(2,'2'));
It d=m.find(5);
if(d!=m.end())
{
printf("找到了\n");
d->second=67;
}
else
printf("沒找到\n");
for (It it = m.begin();it!=m.end();++it)
{
cout<<it->first<<"\t"<<it->second<<endl;
}
icMapCmp c;
c.insert(make_pair(1,'1'));
c.insert(make_pair(3,'3'));
c.insert(make_pair(2,'2'));
for (It1 it1 = c.begin();it1!=c.end();++it1)
{
if(it1->first)
cout<<it1->first<<"\t"<<it1->second<<endl;
}
return 0;
}
參考代碼來自http://www.cnblogs.com/kanego/articles/2408806.html