#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef map<int,string>::value_type mapTyp;
int main()
{
////用insert函数插入pair数据
//map<int,string> mapStudent;
//mapStudent.insert(pair<int,string>(1,"student_one"));
//mapStudent.insert(pair<int,string>(2,"student_two"));
//mapStudent.insert(pair<int,string>(3,"student_three"));
//map<int,string>::iterator iter;
//for (iter=mapStudent.begin();iter!=mapStudent.end();iter++)
//{
// cout<<iter->second<<endl;
//}
以上方法运行结果:
<a href="http://blog.51cto.com/attachment/201105/151726247.jpg" target="_blank"></a>
////用insert函数插入value_type数据
map<int,string> mapStudent;
mapStudent.insert(mapTyp(1,"student_one"));
mapStudent.insert(mapTyp(2,"student_two"));
mapStudent.insert(mapTyp(3,"student_three"));
map<int,string>::iterator iter;
for (iter=mapStudent.begin();iter!=mapStudent.end();iter++)
cout<<iter->first<<" *_* "<<iter->second<<endl;
}
以上运行结果:
<a href="http://blog.51cto.com/attachment/201105/151754426.jpg" target="_blank"></a>
system("pause");
本文转自 韬光星夜 51CTO博客,原文链接:http://blog.51cto.com/xfqxj/562308,如需转载请自行联系原作者