STL第二课
来源:互联网 发布:java 命令模式 实例 编辑:程序博客网 时间:2024/06/05 06:06
①map和unorder_map : map采用平衡二叉树,里面的数据是排序的。unorder_map采用hash,数据没有排序,里面的数据是散列的。
②map可以通过first来访问key,通过second来访问value。
③remove_if的用法
template <class ForwardIterator, class UnaryPredicate> ForwardIterator remove_if (ForwardIterator first, ForwardIterator last, UnaryPredicate pred);
#include <iostream>#include <map>#include <unordered_map>#include <string>#include <vector>#include <algorithm>#include <functional>using namespace std;void foo(const map<int, string>& m){ auto i = m.find(3); if (i == m.end()) { cout<< "Not Found" <<endl; } else { cout << i->second<<endl; }}int main(){ map<int, string> m; //unordered_map<int , string> m1; //采用hash的存储方式,没有排序,查找的时候是常说时间 m[0] = "one"; m[1] = "two"; m[2] = "three"; m[3] = "four"; for (auto i = m.cbegin(); i != m.cend(); ++i) { cout<<"(" <<i->first <<","<< i->second <<")"<<endl; } foo(m); vector<int> vt; vt.push_back(11); vt.push_back(22); vt.push_back(33); vt.push_back(44); vt.push_back(55); vt.erase(remove_if(vt.begin(), vt.end(), [](int e){ return (e % 2 == 1);}), vt.end()); for (auto i = vt.begin(); i != vt.end(); ++i) { cout << *i<<endl; } return 0;}
0 0
- STL第二课
- STL第二课
- Effective STL:第二部分 容器
- 极客班STL第二周笔记
- effective STL 学习笔记 第二条规范
- STL第二章-vector的使用方法
- 《Effective STL》学习笔记(第二部分)
- 《Effective STL》学习笔记(第二部分)
- 极客班STL第二周学习笔记
- GeekBand C++STL第二周笔记
- 范型编程与STL 第二章 算法与区间
- STL 源码分析第二章: 空间配置器理解
- 范型编程与STL--第二章iterator(迭代器)解析
- Geekban极客班C++STL与泛型编程 第二周
- Primer STL笔记第二部分容器与算法
- effective STL 读书笔记——第二章:vector和string
- Boolan STL与泛型编程 第二周笔记
- 读《STL源码剖析》第二章 配置器 has_trivial_destructor
- Final - java
- 如何避免页面刷新导致数据重复写入数据库
- Linux系统编程(33)—— socket编程之TCP程序的错误处理
- libcurl下载限速编程调研
- GPIO 使用及测试方法
- STL第二课
- Linux系统编程(34)—— socket编程之TCP服务器与客户端的交互
- Android fill_parent、wrap_content和match_parent的区别
- Linux系统编程(35)—— socket编程之TCP服务器的并发处理
- 解决耳机不出声
- 一位华为IT总监 职场是学习和感恩的
- 【c++primer】第八章01——标准IO库
- 无以言退 献给高科技企业员工
- 三大秘籍笑傲IT职场