C++ copy()函数
来源:互联网 发布:淘宝客好做吗 编辑:程序博客网 时间:2024/06/16 05:35
function template
<algorithm>
std::copy
template <class InputIterator, class OutputIterator> OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result);
Copy range of elements
Copies the elements in the range [first,last)
into the range beginning at result.The function returns an iterator to the end of the destination range (which points to the element following the last element copied).
The ranges shall not overlap in such a way that result points to an element in the range [first,last). For such cases, see copy_backward.
The behavior of this function template is equivalent to:
123456789
template<class InputIterator, class OutputIterator> OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result){ while (first!=last) { *result = *first; ++result; ++first; } return result;}
示例:
// copy algorithm example#include <iostream> // std::cout#include <algorithm> // std::copy#include <vector> // std::vectorint main () { int myints[]={10,20,30,40,50,60,70}; std::vector<int> myvector (7); std::copy ( myints, myints+7, myvector.begin() ); std::cout << "myvector contains:"; for (std::vector<int>::iterator it = myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
Output:
myvector contains: 10 20 30 40 50 60 70
阅读全文
0 0
- c++STL 中的copy函数
- C++/copy/Destructor(析构函数)
- [C++] next_permutation的函数 与 copy() 函数的用法
- C语言函数string.h 之 内存copy函数memcpy
- C语言函数_string.h 之 内存copy函数memmove
- copy函数
- copy函数
- copy()函数
- copy函数
- c++STL中copy函数的用法解读
- c中几个copy函数的使用细节
- (C/C++学习笔记)Copy构造函数应用场景
- [C++/STL] string字符串关于copy函数的C4996错误
- 利用C语言中的函数实现文件的Copy
- [C++/STL] string字符串关于copy函数的C4996错误
- Value copy & reference copy (C#)
- 【C/C++学院】(6)构造函数/析构函数/拷贝构造函数/深copy浅copy
- C++中拒绝编译器自动生成copy构造函数和copy赋值运算符操作(6)---《Effective C++》
- 文件管理
- Redis学习笔记——初级
- 类和对象
- Hdu5748-Bellovin-最长上升子序列(LIS)
- STL/map的遍历和初始化方式
- C++ copy()函数
- JavaScript闭包详解
- vux中scroller插件,不好发现的神技巧
- PHP环境搭建和编写API接口
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled解决办法
- 51nod 1005 大数加法
- 如何理解项目沟通管理
- Hive on Spark调优
- linux进行vi操作时的查询操作