键值对 一个key对应一个value 允许是任意类型
map以红黑树为底层实现机制
map
例:保存用户信息
map<int,Staff> usermap;
有用到map的地方文件最开头写如下代码(消去警告)
#pragma warning(disable : 4786)
map<key,value> m1;
find(key);
存在:返回迭代器;不存在返回
快速的做验证–根据key查找
返回地址 its=usermap.find(1002);
if(its!=usermap.end())
{
cout<<its->second->getPwd<<" "<<its->second->getName()<<endl;
}
else
{
cout<<"用户不存在,请先注册!"<<enl;
}
只有insert用来插入
usermap.insert(pair<int,Staff>(1001,Staff()));
或者
usermap.insert(make_pair(1001,Staff()));
count函数统计key 有返回1 没有返回0
int icount=usermap.count[1001];