【STL】-迭代器的用法
初始化:
list<char>::iterator pos;
算法:
1. 遍历
for(pos = col1.begin(); pos != col1.end(); ++pos){...}
代码:
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <algorithm>
#include <iterator> //for ostream_iterator&istream_iterator
#include "utility.h"
using namespace std; int main() {
vector<int> v;
vector<int>::iterator pos; for(int i = ; i >= ; i--)
v.push_back(i); //back_inserter调用push_back(), 适用于vector, deque, list
vector<int> col1;
copy(v.begin(), v.end(), back_inserter(col1));
PRINT_ELEMENT(col1); //front_inserter调用push_front(),适用于deque, list
deque<int> col2;
copy(v.begin(), v.end(), front_inserter(col2));
PRINT_ELEMENT(col2); //inserter调用inserter(), 适用于所有容器
set<int> col3;
copy(v.begin(), v.end(), inserter(col3, col3.end()));
PRINT_ELEMENT(col3); //ostream iterator
copy(col3.rbegin(), col3.rend(), ostream_iterator<int>(cout, " "));
cout << endl; //istream iterator
vector<string> col4;
copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(col4));
PRINT_ELEMENT(col4);
return ;
}
输出:
$ ./a.exe
content: content: content: abd adfasdf assdfasdf afewaf 1a ` adsfasdf
content:
abd adfasdf assdfasdf afewaf 1a ` adsfasdf
【STL】-迭代器的用法的更多相关文章
- STL迭代器笔记
STL迭代器简介 标准模板库(The Standard Template Library, STL)定义了五种迭代器.下面的图表画出了这几种: input output \ ...
- C++中的STL中map用法详解(转)
原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解 Map是STL的一个关联容器,它提供 ...
- C++-STL:vector用法总结
目录 简介 用法 1. 头文件 2. vector的声明及初始化 3. vector基本操作 简介 vector,是同一类型的对象的集合,这一集合可看作可变大小的数组,是顺序容器的一种.相比于数组,应 ...
- 一步一步的理解C++STL迭代器
一步一步的理解C++STL迭代器 "指针"对全部C/C++的程序猿来说,一点都不陌生. 在接触到C语言中的malloc函数和C++中的new函数后.我们也知道这两个函数返回的都是一 ...
- STL 迭代器 iterator const
STL迭代器很多时候可以当成指针来使用. 但是指针一般可以用const来控制访问. 那迭代器呢. #include <iostream> #include <vector> u ...
- STL的其他用法(adjacent_find, find_first_of, sort_heap, merge, binary_search)总结
2017-08-20 17:26:07 writer:pprp 1.adjacent_find() 下面是源码实现: template <class ForwardIterator> Fo ...
- Python迭代器的用法,next()方法的调用
迭代器的用法: 首先说两个概念,一个是可迭代的对象,一个是迭代器对象,两个不同 可迭代的(Iterable):就是可以for循环取数据的,比如字典.列表.元组.字符串等,不可使用next()方法. 迭 ...
- STL迭代器的使用、正向、逆向输出双向链表中的所有元素
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- list 迭代器的用法
string strTemp; list<string> strList; char *ch = new char[]; strcpy( ch , ""); strTe ...
- 【STL 源码剖析】浅谈 STL 迭代器与 traits 编程技法
大家好,我是小贺. 点赞再看,养成习惯 文章每周持续更新,可以微信搜索「herongwei」第一时间阅读和催更,本文 GitHub : https://github.com/rongweihe/Mor ...
随机推荐
- 图标下载网站 http://www.easyicon.net/
图标下载网站 http://www.easyicon.net/
- [css] 垂直居中方法
原文链接:http://www.cnblogs.com/2050/p/3392803.html 一.text-algin:center; 适用于行内元素水平居中,如图片.按钮.文字, 但是在IE67下 ...
- 养成好的JAVA编码习惯
原文:http://blog.csdn.net/lifuxiangcaohui/article/details/25231027 最近的机器内存又爆满了,除了新增机器内存外,还应该好好review一下 ...
- org.apache.hadoop.hbase.TableExistsException: hbase:namespace
Problem is here : https://community.cloudera.com/t5/Storage-Random-Access-HDFS/HMaster-not-starting- ...
- Linux定时任务Crontab详解_定时备份
文章来源:http://blog.chinaunix.net/uid-7552018-id-182133.html 今天做了个数据库的备份脚本,顺便系统得学习一下Linux下定时执行脚本的设置.Lin ...
- XML到底是什么
http://www.w3school.com.cn/xml/xml_intro.asp w3school介绍 XML XML 被设计用来传输和存储数据. HTML 被设计用来显示数据. 应该掌握的 ...
- j2ee四大作用域pagecontext,request,session,ServletContext(转)
转自:(http://www.5ycode.com/63) 在JSP页面中的对象,包括用户创建的对象(例如,JavaBean对象)和JSP的隐含对象,都有一个范围属性.范围定义了在什么时间内,在哪一个 ...
- nodeschool.io 8
~~ HTTP COLLECT ~~ Write a program that performs an HTTP GET request to a URL provided toyou as the ...
- CentOS 6.x安装配置
简述 VMware可以创建多个虚拟机,每个虚拟机上都可以安装各种类型的操作系统.安装方法也有很多种.下面,主要以ISO镜像安装为例,介绍CentOS 6.x的安装过程及相关的参数设置. 简述 创建虚拟 ...
- Qt之QRoundProgressBar(圆形进度条)
简述 QRoundProgressBar类能够实现一个圆形进度条,继承自QWidget,并且有和QProgressBar类似的API接口. 简述 详细说明 风格 颜色 字体 共有函数 共有槽函数 详细 ...