stl map3
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main( )
{
//用insert函数插入value_type 数据
map<int,string>stu;
int n, i;
stu.insert(map<int,string>::value_type(1,"bcdefg"));
stu.insert(map<int,string>::value_type(4,"abcdef"));
stu.insert(map<int,string>::value_type(2,"efghfg"));
map<int,string>::iterator iter;
n = stu.size( );
//map的遍历 应用前向迭代器
for ( iter = stu.begin( ); iter != stu.end( ); iter++)
cout<<iter->first<<" "<<iter->second<<endl;
//map的大小
cout<<n<<endl;
//map的遍历 应用反向迭代器
map<int,string>::reverse_iterator it;
for ( it = stu.rbegin( ); it != stu.rend( ); it++)
cout<<it->first<<" "<<it->second<<endl;
puts("");
return 0;
}
posted on 2011-07-28 21:38 more think, more gains 阅读(148) 评论(0) 收藏 举报
浙公网安备 33010602011771号