#include<vector>
#include<iostream>
#include <list>
#include "string"
#include "memory"
#include "map"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
map<string, int> TestMap;
map<string,int>::iterator BTestMapIterator;
map<string, int>::iterator ETestMaplterator;
string getstring1 ;
string getstring2 ;
char getchars[4];
cout << "please enter several groups,two strings are a groups,each char separated by a space and each group separated by a enter" << endl;
//enter map data
while (true)
{
cin >> getstring1;
cin >> getstring2;
//c_str is string change to char*
if (strcmp("end", getstring1.c_str()) == 0 || 0 == strcmp("end", getstring2.c_str()))
{
break;
}
TestMap.insert(make_pair(getstring1, atoi(getstring2.c_str())));
}
//show the map
BTestMapIterator = TestMap.begin();
ETestMaplterator = TestMap.end();
cout << "the map is :" << endl;
for (; BTestMapIterator != ETestMaplterator;BTestMapIterator++)
{
cout << BTestMapIterator->first<<"->"<<BTestMapIterator->second<<endl;
}
//search the data
cout << "enter the key you want to search" << endl;
cin >> getstring1;
if (TestMap.find(getstring1.c_str())!=TestMap.end())
{
cout << "you want to search data is " << TestMap.find(getstring1.c_str())->second << endl;
}
//delete the data
TestMap.erase(TestMap.find(getstring1.c_str()));
cout << "the data had been deleted,now,the map is" << endl;
for (BTestMapIterator = TestMap.begin(); BTestMapIterator != TestMap.end();BTestMapIterator++)
{
cout << BTestMapIterator->first << "->" << BTestMapIterator->second << endl;
}
getchar();
getchar();
return 0;
}