std::copy() & std::back_inserter()
来源:互联网 发布:java工程反编译 编辑:程序博客网 时间:2024/05/21 23:31
std::copy
template<class InputIterator, class OutputIterator> OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result){ while (first!=last) { *result = *first; ++result; ++first; } return result;}
std::copy()函数和strcpy()的实现类似,只是参数类型由char 变为 iterator
// 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() ); //参数 first last result // [first,last) 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
std::back_inserter()
// back_inserter example#include <iostream> // std::cout#include <iterator> // std::back_inserter#include <vector> // std::vector#include <algorithm> // std::copyint main () { std::vector<int> foo,bar; for (int i=1; i<=5; i++) { foo.push_back(i); bar.push_back(i*10); } std::copy (bar.begin(),bar.end(),back_inserter(foo));//back_inserter() 把当前iterator插入到foo容器尾部,返回类型是一个叫back_insert_iterator的东西.. std::cout << "foo contains:"; for ( std::vector<int>::iterator it = foo.begin(); it!= foo.end(); ++it ) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
Output:foo contains: 1 2 3 4 5 10 20 30 40 50
0 0
- std::copy() & std::back_inserter()
- std::copy()和std::back_inserter()用法
- std::copy
- std::copy
- std::pair, std::copy, std::lower_bound, std::back_insert使用
- std::copy 的用法
- 【C++】std::copy
- std::copy 详解
- std::copy详解
- 使用std::copy将std::map输出到std::cout
- std
- std
- std
- C++ STL std::copy 详解
- std::copy函数 和 ostream_iterator
- C++ STL std::copy 详解
- std::map 中调用 std::copy 的方法
- std::map 中调用 std::copy 的方法
- python列表与元组的区别
- 对话框
- 740C.Alyona and mex codeforces
- App引导页面的常用布局和实现
- 正则中\\b和\\B的区别及注意事项
- std::copy() & std::back_inserter()
- 应对冒充者综合症
- python ------ 自动发送邮件
- nodejs Async 详解
- LCM Walk HDU
- 详解PHP的执行原理和流程
- 蔬菜大棚控制与WEB
- 数组复制
- 事件分发学习笔记二(ViewGroup篇)