文档介绍:cqs_2012
experiments to theory and person puter
算法之旅,直奔<algorithm>之五 copy
分类: algorithm C++ 2013-12-14 10:57 209人阅读评论(0) 收藏举报
algorithmvs2010
copy(vs2010版本)
引言
copy是我学习总结<algorithm>的第五篇,这个太好理解了,就是简简单
单的copy。
作用
copy的作用是具有连续地址的一堆数据复制到指定的容器里,并返回这
个容器。
原理如下
template<class InputIterator, class OutputIterator>
OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result)
{
while (first!=last) {
*result = *first;
++result; ++first;
}
return result;
}
实验
把数据集合{10,20,30,40,50,60,70}复制到容器--myvector里,并输
出。
     
1
2
代码
#include <iostream> // std::cout
#include <algorithm> // std::copy
#include <vector> // std::vector
int main ()
{
int myints[]={10,20,30,40,50,60,70};
std::vector<int> myvector (7);
std::copy ( myints, myints+7, () );
std::cout << "myvector contains:";
for (std::vector<int>::iterator it = (); it!=(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
system("pause");
return 0;
}
更多
上一篇:算法之旅,直奔<algorithm>之四 binary_search
下一篇:算法之旅,直奔<algorithm>之六 copy_backward
顶
0
踩
0
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
核心技术类目
全部主题 Java VPN Android iOS ERP IE10 Eclipse CRM JavaScript Ubuntu NFC WAP jQuery 数据库 BI HTML5
Spring Apache Hadoop .NET API HTML SDK IIS Fedora XML LBS Unity Splashtop ponents
Windows Mobile Rails QEMU KDE C