#include <iostream>
using namespace std;
#include <vector> //动态数组
#include <algorithm>//算法 void PrintVector(int v) {
cout << v<<" "; } /*
STL
容器算法迭代器
基本语法
*/
void test01() {
vector<int> v; //定义一个容器 指定存放的元素类型
v.push_back(); //把元素放入容器尾部
v.push_back();
v.push_back();
v.push_back();
//STL foreach函数
//容器提供迭代器
//vector<int>::iterator 迭代器类型 等号重载 返回迭代器类型(指针)
vector<int>::iterator pBegin = v.begin();
vector<int>::iterator pEnd = v.end();
//容器中可能存放基础数据类型,也可能存放自定义数据类型
//PrintVector 回调函数 将每个参数传入,并处理
for_each(pBegin, pEnd, PrintVector); } //容器也可以存放自定义类型的数据
class Person {
public:
Person(int age, int id) :age(age), id(id) {};
public:
int age;
int id; }; void test02() {
//创建V 并制定容器元素类型为Person
vector<Person> v;
Person p1(, ), p2(, );
v.push_back(p1);
v.push_back(p2);
v.pop_back(); for (vector<Person>::iterator it = v.begin(); it != v.end(); it++) {
cout << (*it).age << " " << (*it).id << " " << endl;
//vector<Person> v; <>里放的是什么 取*就是什么类型
}
} //algorithm
//容器存放person* 进行打印 自练
//容器里面嵌套容器 一个容器作为另一个容器的元素 int main() {
test02();
}

STL 小白学习(1) 初步认识的更多相关文章

  1. STL 小白学习(10) map

    map的构造函数 map<int, string> mapS; 数据的插入:用insert函数插入pair数据,下面举例说明 mapStudent.insert(pair<, &qu ...

  2. STL 小白学习(9) 对组

    void test01() { //构造方法 pair<, ); cout << p1.first << p1.second << endl; pair< ...

  3. STL 小白学习(8) set 二叉树

    #include <iostream> using namespace std; #include <set> void printSet(set<int> s) ...

  4. STL 小白学习(7) list

    #include <iostream> using namespace std; #include <list> void printList(list<int>& ...

  5. STL 小白学习(5) stack栈

    #include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace ...

  6. STL 小白学习(6) queue

    //queue 一端插入 另一端删除 //不能遍历(不提供迭代器) 不支持随机访问 #include <queue> #include <iostream> using nam ...

  7. STL 小白学习(4) deque

    #include <iostream> #include <deque> //deque容器 双口 using namespace std; void printDeque(d ...

  8. STL 小白学习(3) vector

    #include <iostream> using namespace std; #include <vector> void printVector(vector<in ...

  9. STL 小白学习(2) string

    #include <iostream> using namespace std; #include <string> //初始化操作 void test01() { //初始化 ...

随机推荐

  1. 你不知道的JavaScript-1.作用域是什么

    作用域是一套规则,用于确定在何处以及如何查找变量.函数等(标识符).如果查找的目的是对变量进行赋值,那么就会使用 LHS 查询:如果目的是获取变量的值,就会使用 RHS 查询. 赋值操作符会导致 LH ...

  2. [LeetCode] 236. Lowest Common Ancestor of a Binary Tree_ Medium tag: DFS, Divide and conquer

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  3. DOIS 2019 DevOps国际峰会北京站来袭~

    DevOps 国际峰会是国内唯一的国际性 DevOps 技术峰会,由 OSCAR 联盟指导.DevOps 时代社区与高效运维社区联合主办,共邀全球80余名顶级专家畅谈 DevOps 体系与方法.过程与 ...

  4. git bash支持中文

    打开Git Bash窗口-->右键-->Options-->text Locale:设置为zh_CN Charachter set:设置为UTF-8 保存,重新打开Git Bash, ...

  5. SPP空间金字塔池化技术的直观理解

    空间金字塔池化技术, 厉害之处,在于使得我们构建的网络,可以输入任意大小的图片,不需要经过裁剪缩放等操作. 是后续许多金字塔技术(psp,aspp等)的起源,主要的目的都是为了获取场景语境信息,获取上 ...

  6. laravel自定义验证

    1.在控制器中直接写验证$this->validate($request, [ 'video_ids' => [ function($attribute, $value, $fail) { ...

  7. 新装Windows Server 2008 r2无法连接有线网络

    新装的Windows Server 2008 r2没有网卡驱动,所以没有网络适配器. 首先,我在相同的型号电脑上查到这个主板的网卡驱动安装的是Intel(R) Ethernet Coinnection ...

  8. Spring Boot IoC 容器初始化过程

    1. 加载 ApplicationContextInializer & ApplicationListener 2. 初始化环境 ConfigurableEnvironment & 加 ...

  9. ProcessExplorer使用分享

    工具描述 Process Explorer使用个轻量级的进程管理器,是由Sysinternals出品的免费工具,请猛击这里下载最新版本使用. 以下是官方介绍的翻译: “想知道是那个程序打开了某个文件或 ...

  10. JavaScript Dom 查找

    JavaScript Dom 查找 一.直接查找 获取单个元素 document.getElementById('i1') 获取多个元素(列表数组) document.getElementsByTag ...