struct mycompare{ //写一个仿函数
bool operator()(MyKey key1, MyKey key2){
return key1.mIndex > key2.mIndex;
}
};
void test02(){
map<MyKey, int, mycompare> mymap; //自动排序,自定数据类型,咋排?
mymap.insert(make_pair(MyKey(1, 2), 10));
mymap.insert(make_pair(MyKey(4, 5), 20));
for (map<MyKey, int, mycompare>::iterator it = mymap.begin(); it != mymap.end();it ++){
cout << it->first.mIndex << ":" << it->first.mID << " = " << it->second << endl;
}
}
map中插入自定义类型的key
最新推荐文章于 2024-05-05 01:28:35 发布