STL学习
来源:互联网 发布:python 游戏编程 编辑:程序博客网 时间:2024/05/29 10:11
1、利用ostream_iterator输出容器或数组内容
#include <iostream>#include <iterator>#include <algorithm>#include <vector>using namespace std;void showArry(int *arry,int len){ copy(arry,arry+len,ostream_iterator<int>(cout, " "));}void showVector(vector<int> intVector){ copy(intVector.begin(),intVector.end(),ostream_iterator<int>(cout, " "));}int main(){ int arry[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"int数组内容:"<<endl; showArry(arry,10); cout<<endl; vector<int> intVector(10); copy(arry,arry+10,intVector.begin()); cout<<"int向量内容:"<<endl; showVector(intVector); return 0;}
2、利用for_each输出容器或数组内容
#include <iostream>#include <algorithm> // Need for_each()#include <vector>using namespace std;void show(int i){ cout<<i<<" ";}int main(){ int arry[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"int数组内容:"<<endl; for_each(arry,arry+10,show); cout<<endl; vector<int> intVector(10); copy(arry,arry+10,intVector.begin()); cout<<"int向量内容:"<<endl; for_each(intVector.begin(),intVector.end(),show); return 0;}
0 0
- 学习STL -- STL 简介
- STL学习
- STL学习
- STL学习
- Stl 学习
- STL学习
- 学习STL
- STL学习
- STL 学习
- 学习STL
- 学习STL
- STL学习
- STL学习
- STL学习
- stl学习
- STL 学习
- STL学习
- STL 学习
- ContentProvider和Uri详解
- 录制badboy脚本的时候弹出脚本错误
- java
- Chrome开发者工具不完全指南(一、基础功能篇)
- SpringMVC学习
- STL学习
- cisco lan switching cli
- JPA
- HDU5443 线段树 + 裸 + 求任意区间最大值
- xtype属性整理
- Maven package war包时,指定本地jar包
- 轮盘赌算法
- 【图】:有向图中两点间的路径
- 通过VBA将excel数据导入至word文档