【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 ...
随机推荐
- html5 和css3的小知识!
阿里web字体的使用 (1)进入官网 点击webfont (2)输入对应的文字 然后选择添加字体 (3)可以直接引用线上地址或者本地下载,引用线上地址需要添加http,(在服务器环境下可以不用),如 ...
- Android网络编程系列 一 JavaSecurity之JSSE(SSL/TLS)
摘要: Java Security在Java存在已久了而且它是一个非常重要且独立的版块,包含了很多的知识点,常见的有MD5,DigitalSignature等,而Android在Java Se ...
- [css] 认识margin
原文链接http://www.zhangxinxu.com/wordpress/2009/08/css-margin%E7%9A%84%E7%9B%B8%E5%85%B3%E5%B1%9E%E6%80 ...
- 转:为什么C++中空类和空结构体大小为1?
参考:http://www.spongeliu.com/260.html 为什么C++中空类和空结构体大小为1? On November 17, 2010, in C语言, 语言学习, by spon ...
- D3.js 插入元素,删除元素
插入元素涉及的函数有两个: 一.append():在选择集末尾插入元素 假设有三个段落元素 <p>Apple</p> <p>Pear</p> <p ...
- codeblock报__objc_class_name_xxx问题
添加来一个class文件,在其他文件调用时,报下面这个错误: undefined reference to `__objc_class_name_Test' 右击Test这个类的文件弹出Propert ...
- css-高度自适应的问题(body高度问题)
css-高度自适应的问题 对象height:100%并不能直接产生效果,是因为跟其父对象有关. #center{ height:100%; } 上面的css样式是无效的,不会产生任何效果. 需要改写: ...
- 【转】 STL中的set容器的一点总结
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...
- 【Problem solved】发现输入法都是仅桌面使用,无法输入中文时
你打开命令提示符输入CTFMON就可以啦.
- mouseover,mouseenter,mouseleave,mouseout
mouseover和mouseout对应 //鼠标移入移出触发该元素及子元素 mouseenter和mouseleave对应 //鼠标移入移出只触发该元素 看完例子即可知道其区别: mouseover ...