STL之map笔记
2011-02-19 22:03
190 查看
#include "stdafx.h"
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
using namespace std;
bool gt_42(const pair<const string, int>& r)
{return r.second>42;}
int main(int argc, char* argv[])
{
printf("Hello World!/n");
typedef map<string,int> U_map;
U_map umap;
umap.insert(map<string,int>::value_type("a",11));//下面网址上说这个方法比umap["a"]=1更有效率,节省开销。
umap.insert(map<string,int>::value_type("b",312));
typedef map<string ,int>::const_iterator MI;
MI i=find_if(umap.begin(),umap.end(),gt_42); //iterator是一个pair对象。
cout<<(*i).second<<endl<<(*i).first<<endl; //(*i)代表map中一个键值对,second取第二个值。
return 0;
//map的介绍网址
//http://wenku.baidu.com/view/d59095ea6294dd88d0d26b41.html
}
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
using namespace std;
bool gt_42(const pair<const string, int>& r)
{return r.second>42;}
int main(int argc, char* argv[])
{
printf("Hello World!/n");
typedef map<string,int> U_map;
U_map umap;
umap.insert(map<string,int>::value_type("a",11));//下面网址上说这个方法比umap["a"]=1更有效率,节省开销。
umap.insert(map<string,int>::value_type("b",312));
typedef map<string ,int>::const_iterator MI;
MI i=find_if(umap.begin(),umap.end(),gt_42); //iterator是一个pair对象。
cout<<(*i).second<<endl<<(*i).first<<endl; //(*i)代表map中一个键值对,second取第二个值。
return 0;
//map的介绍网址
//http://wenku.baidu.com/view/d59095ea6294dd88d0d26b41.html
}
相关文章推荐
- STL中map, list, and pair的学习笔记
- C++学习笔记--STL(映射:map)
- STL笔记(1)map
- C++ STL学习笔记一----map
- C++ STL--map映照容器学习笔记
- STL笔记(1)map
- C++ STL学习笔记九 map映照容器
- C++ Primer 学习笔记_35_STL实践与分析(9)--map种类(在)
- STL笔记(5)-map/multimap
- STL 笔记(二) 关联容器 map、set、multimap 和 multimap常用函数
- C++ STL关联容器 set和map学习笔记
- STL 笔记(二) 关联容器 map、set、multimap 和 multimap
- C++ Primer 学习笔记_35_STL实践与分析(9)--map种类(在)
- C++ Primer 学习笔记_36_STL实践与分析(10)--map类型(下
- C++笔记:STL扩展hash_map
- 11/7/8 STL 映射容器 map< K , T > 学习笔记
- 【C++ 学习笔记】:STL-map
- STL学习笔记----6.容器 map 和 multimap
- C++ STL学习笔记十二 hash_map映照容器
- 【学习笔记】C++高级程序设计:STL:Map 和 Multimap