Construct vector (构建vector)
2016-07-04 20:26
239 查看
#include <iostream> #include <vector> using namespace std; int main () { //简单地说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。 // constructors used in the same order as described above: vector<int> first; // empty vector of ints vector<int> second (4,100); // four ints with value 100 vector<int> third (second.begin(),second.end()); // iterating through second vector<int> fourth (third); // a copy of third // the iterator constructor can also be used to construct from arrays: int myints[] = {16,2,77,29}; vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) ); cout<<"The content of first are:"; for(vector<int>::iterator it = first.begin(); it!=first.end();++it) cout<<" "<<*it; cout<<"\n" ; cout<<"The content of second are:"; for(vector<int>::iterator it = second.begin(); it!=second.end();++it) cout<<" "<<*it; cout<<"\n" ; cout<<"The content of third are:"; for(vector<int>::iterator it = third.begin(); it!=third.end();++it) cout<<" "<<*it; cout<<"\n" ; cout<<"The content of fourth are:"; for(vector<int>::iterator it = fourth.begin(); it!=fourth.end();++it) cout<<" "<<*it; cout<<"\n" ; cout << "The contents of fifth are:"; for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it) cout << ' ' << *it; cout <<"\n"; return 0; }
相关文章推荐
- paper 80 :目标检测的图像特征提取之(一)HOG特征
- php命名空间
- android sudio 打包资料汇总
- 基于物品的协同过滤算法:理论说明,代码实现及应用
- 雅克比矩阵的scala实现
- R下一些函数
- W3AF插件编写
- 【matlab】利用matlab编写启发式算法
- 【原】Maven解决jar冲突调试步骤:第三方组件引用不符合要求的javassit导致的相关异常
- 链表的Java实现
- 交叉编译知识解析(二) —— 交叉编译器的名字的命名规则
- RecyclerView通用适配器Adapter,对Adapter的封装
- 百度一道笔试题
- 秦晖:王小波是一个自由主义思想家吗?
- RTSP协议介绍
- php5中this关键字用法讲解
- 记搜狗机器学习实习生面试
- java.lang.NoClassDefFoundError: org/springframework/beans/factory/support/DefaultListableBeanFactory
- 2.1 nagios 安装
- java框架之spring基础应用