首页 > 编程语言 > 详细

STL算法之函数copy

时间:2018-06-24 21:26:41      阅读:197      评论:0      收藏:0      [点我收藏+]

STL算法之copy

 copy(beg, end, dest) //dest表示输入迭代器

#include <iostream>  
#include <algorithm>  
#include <vector>  
using namespace std;

int main()
{
	int myints[] = { 10, 20, 30, 40, 50, 60, 70 };
	vector<int> myvector;
	vector<int>::iterator it;

	myvector.resize(7);   // 为容器myvector分配空间  

	copy(myints, myints + 7, myvector.begin());
	cout << "myvector contains: ";
	for (it = myvector.begin(); it != myvector.end(); ++it)
		cout << " " << *it;
	cout << endl;

	copy(myints + 1, myints + 7, myints);
	cout << "myints contains: ";
	for (size_t i = 0; i < 7; ++i)
		cout << " " << myints[i];
	cout << endl;

	return 0;
}

输出结果

技术分享图片

 

STL算法之函数copy

原文:https://www.cnblogs.com/sunbines/p/9221779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!