c++ map

来源:互联网 发布:公务员面试报网络班 编辑:程序博客网 时间:2024/06/15 10:33

例如 map<int,int> test

test[0] =0;

test[1]=1;


若要判断map中是否存在某个元素,要使用

map<int,int>::iterator it = test.find(key);

if( it == test.end()) //不存在

{

xxxx

}


注意不要使用

int xx = test[key]; //这里就相当与复制了,map【0】 = key;


原创粉丝点击