vector操作
2015-06-08 18:07
295 查看
1、一次性打印vector中的所有元素
2、将两个vector元素组合到一个vector中
3、利用函数 max_element,min_element,distance可以获取Vector中最大、最小值的值以及位置索引
2、将两个vector元素组合到一个vector中
3、利用函数 max_element,min_element,distance可以获取Vector中最大、最小值的值以及位置索引
</pre><p></p><pre name="code" class="cpp">#include <vector> #include <iterator> #include <algorithm> #include <iostream> using namespace std; int main() { vector<float> A; A.push_back(1.0); A.push_back(2.0); A.push_back(3.0); vector<float>B; B.push_back(4.0); B.push_back(5.0); B.push_back(6.0); cout<<"***A******"<<endl; copy (A.begin(), A.end(), ostream_iterator<float> (cout, "\n"));// 打印A的元素 cout<<"***B******"<<endl; copy (B.begin(), B.end(), ostream_iterator<float> (cout, "\n")); cout<<"****new A******"<<endl; A.insert(A.end(),B.begin(),B.end());//合并B到A copy (A.begin(), A.end(), ostream_iterator<float> (cout, "\n")); vector<double>::iterator maxValue = max_element(begin(A),end(A)); cout << "Max element is " << *maxValue<< " at position " <<distance(begin(A),maxValue)<<endl; auto minValue = std::min_element(begin(A), std::end(A)); cout << "min element is " << *minValue<< " at position " <<distance(begin(A),maxValue)<<endl; return 0; }
相关文章推荐
- 思科路由开启NAT
- Ext配置对象
- SCORM Explained
- XML操作举例→实现用户登录
- hdu 5142 NPY and FFT
- 个人拾遗!数组的拷贝等
- 程序员每天-7
- chroot详解
- 网盘的推广引流手段
- C#泛型在unity3D中的运用
- 使用VC++压缩解压缩文件夹
- 配置文件设置上传文件大小、超时时间等
- extern关键字
- CentOS 将网卡设置成eth0
- inotify-tools时实调用rsync同步文件
- Android 定位详解(显示自己想要的定位信息)
- Horizontal---ProgressBar
- [bootstrap] 修改字体
- Dispose的重写
- 《Linux内核设计与实现》读书笔记之进程地址空间