【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 ...
随机推荐
- 代码中特殊的注释技术——TODO、FIXME和XXX的用处
本文内容概要: 代码中特殊的注释技术--TODO.FIXME和XXX的用处. 前言:今天在阅读Qt Creator的源代码时,发现一些注释中有FIXME英文单词,用英文词典居然查不到其意义!实际上, ...
- 彻底理解ThreadLocal
ThreadLocal是什么 早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地 ...
- Maven——eclipse中使用Maven创建Web项目
原文:http://www.cnblogs.com/xdp-gacl/p/4054814.html 一.创建Web项目 1.1 选择建立Maven Project 选择File -> New - ...
- maven Connection refused: connect
现象: 本地可以访问错误提示中的地址.但使用maven无法下载jar包. 环境: 浏览器上网需要使用代理 解决方法: 设置成正常代理可以.具体方法可以下载一个代理工具.只要IE配置成能直接访问http ...
- Windows 内存架构
理解 Virtual Memory, Physical Memory, Committed Memory, Page File, Working Set, Modified Pages, Standb ...
- Eclipse启动tomcat时报错:Multiple Contexts have a path of "/xxx"
今天使用Eclipse启动tomcat部署项目时,遇到一个奇怪的错误: Could not publish server configuration for Tomcat v6.0 Server at ...
- HM中再增加一路自己的entropy coder
compressSlice 中一开始的entropy coder 设置: // set entropy coder if( m_pcCfg->getUseSBACRD() ) { m_pcSba ...
- Hbase之批量删除数据
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...
- easyui combobox 智能提示搜索
<!-- 获取机会点名称列表 --><script> function initOpportunityNameFuzzyQuery() { $('#jihuidianmingc ...
- php imagecreatetruecolor输出字符符或验证码
$img = imagecreatetruecolor(100,100); //创建真彩图像资源 $color = imagecolorAllocate($img,200,200,200); //分配 ...