map映射
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
using namespace std;
typedef map <int ,string> templatemap;
templatemap testmap;
templatemap::iterator Find(int nID)
{
return testmap.find(nID);
}
string GetElement(int nID)
{
templatemap::iterator iter = Find(nID);
if(iter == testmap.end())
return NULL;
else
return iter->second;
}
void main()
{
string data2="getid()";
string data1="gethp()";
string data="getmp()";
testmap[1]=data;
testmap[2]=data1;
testmap[3]=data2;
for (templatemap::iterator iter = testmap.begin();iter != testmap.end(); iter++)
{
cout<<iter->first<<" ";
string data2=iter->second;
for(int i=0;i<strlen(data2.c_str());i++)
{
cout<<data2[i];
}
cout<<endl;
}
if(Find(3)==testmap.end())
return;
string data4=GetElement(3);
cout<<3<<" ";
for(int i=0;i<strlen(data4.c_str());i++)
{
cout<<data4[i];
}
getchar();
}