#include <map>
#include <iostream>
int main( )
{
using namespace std;
map<string,int> person;
person.insert(make_pair("strength",200));
pair<map<string, int>::iterator, bool> ret = person.insert(make_pair("strength",100));
cout << "ret : " << ret.second << endl;
person.insert(make_pair("defence",50));
person.insert(make_pair("magic",10));
person.insert(make_pair("crtical strike",5));
person.insert(make_pair("crtical strike",20));
map<string,int>::iterator iter;
map<string,int>::iterator iter2;
iter = person.find("crtical strike");
cout << "crtical strike is " << iter->second << endl;
iter = person.begin();
iter2 = person.insert(person.end(),make_pair("health",30));
cout<<endl;
cout << "iter2 : " << iter2->first<< " : " << iter2->second << endl;
cout<<endl;
for(;iter!= person.end();iter++)
{
cout << iter-> first << " : " << iter->second << endl;
}
cout<<endl;
cout << "Erase" << endl;
int count = person.erase("health");
if(count == 1)
{
cout << "health is erased" << endl;
}
else
{
cout << "can't find health" << endl;
}
iter = person.begin();
for(;iter!= person.end();iter++)
{
if(iter->first == "magic")
{
cout << "find magic!" << endl;
break;
}
}
person.erase(iter);
iter = person.begin();
cout << "****************list of person:**************" << endl;
for(;iter!= person.end();iter++)
{
cout << iter-> first << " : " << iter->second << endl;
}
cout << endl;
cout << "erase all" << endl;
map<string,int>::iterator erase_begin = person.begin();
map<string,int>::iterator erase_end = person.end();
person.erase(erase_begin,erase_end);
cout << "person size is " << person.size() << endl;
return 0;
}