#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. Spring框架的第四天(整合ssh框架)

    ## Spring框架的第四天 ## ---------- **课程回顾:Spring框架第三天** 1. AOP注解方式 * 编写切面类(包含通知和切入点) * 开启自动代理 2. JDBC模板技术 ...

  2. transition属性值

    一.transition-property: transition-property是用来指定当元素其中一个属性改变时执行transition效果,其主要有以下几个值:none(没有属性改变):all ...

  3. 笔记02 linux的一些命令sed

    #!/bin/bash # dataformat=`date +%Y-%m-%d-%H-%M` #进行文件件cp并重命名 nginx_home=/opt/modules/nginx-1.12/ cp ...

  4. 2019/4/2 wen 多态、抽象

  5. poj2115 C Looooops(exgcd)

    poj2115 C Looooops 题意: 对于C的for(i=A ; i!=B ;i +=C)循环语句,问在k位存储系统中循环几次才会结束. 若在有限次内结束,则输出循环次数. 否则输出死循环. ...

  6. 如何利用cURL和python对服务端和web端进行接口测试

    工具描述 cURL是利用URL语法在命令行方式下工作的文件传输工具,是开源爱好者编写维护的免费工具,支持包括Windows.Linux.Mac等数十个操作系统,最新版本为7.27.0,但是我推荐大家使 ...

  7. elasticsearch 索引备份恢复

    备份脚本 es_backup.sh : #!/bin/bash#备份昨天数据,删除30天前索引 host=`hostname`address="xxx@xxx.com" es_us ...

  8. MATLAB raw格式转为bmp格式

    今天是第一天写博客,哈哈哈!把完成的数字图像作业放上来和大家一起分享一下! 如果有什么问题,希望大家和我多多交流 1518234852@qq.com width=512; height=512; im ...

  9. 原生JS实现简易转盘抽奖

    我爱撸码,撸码使我感到快乐. 大家好,我是Counter. 本章带大家来简单的了解下原生JS实现转盘抽奖. 因为主要涉及到JS,在这里HTML和CSS起到的功能就没有那么重要, 因此,没有过多的阐述H ...

  10. oracle 根据出生日期计算年龄的年月日

    select years,months,abs( trunc( newer_date- add_months( older_date,years*12+months ) ) ) days from ( ...