简单代码。随着学习会慢慢改
#include<map>
#include<string>
#include<iostream>
using namespace std;
int main()
{
map <int,string>map_student;
map_student.insert(pair<int,string>(1,"student_one"));
map_student.insert(map<int,string>::value_type(2,"student_two"));
map_student[0] = "student_three";
map<int,string>::iterator iter;
for(iter = map_student.begin() ;iter != map_student.end();iter++)
{
cout << iter -> first <<" " << iter -> second << endl;
}cout << endl;
iter = map_student.find(1);
if(iter != map_student.end())
{
cout << iter -> second << endl;
}
else
cout << "not find" << endl;
cout << endl;
iter = map_student.find(1);
map_student.erase(iter);
for(iter = map_student.begin() ;iter != map_student.end();iter++)
{
cout << iter -> first <<" " << iter -> second << endl;
}cout << endl;
}
希望有用