65,187
社区成员




map<int,string> testMap;
int index = 0;
cout<<testMap[index];
// map::find
#include <iostream>
#include <map>
using namespace std;
int main ()
{
map<char,int> mymap;
map<char,int>::iterator it;
mymap['a']=50;
mymap['b']=100;
mymap['c']=150;
mymap['d']=200;
it=mymap.find('b');
mymap.erase (it);
mymap.erase (mymap.find('d'));
// print content:
cout << "elements in mymap:" << endl;
cout << "a => " << mymap.find('a')->second << endl;
cout << "c => " << mymap.find('c')->second << endl;
return 0;
}
map<int,string> testMap;
int index = 0;
testMap[index] = "abc";//,这句相当于insert一个元素到map里,
//不加这句程序直接挂掉,因为你的map是空的
cout<<testMap[index];