推荐2个c++函数库,类定义的资料库:

http://en.cppreference.com/w/cpp/algorithm/copy

http://www.cplusplus.com/reference/algorithm/copy/?kw=copy

---------------------------------------------------------------------------------------------------------------

Defined in header <algorithm>
template< class InputIt, class OutputIt >
     OutputIt copy( InputIt first, InputIt last, OutputIt d_first );

Copies the elements in the range, defined by [first, last), to another range beginning at d_first.

Parameters

first, last

Input iterators to the initial and final positions in a sequence to be copied. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.

c++中的区间几乎都是左开右闭的,包括一些类的构造函数,比如 int a[5] = { 1, 2, 3, 4, 5};  set<int> s(&a[0], &a[4]); s里只会插入{ 1,2,3,4 }这4个元素。

d_first

Output iterator to the initial position in the destination sequence.
            This shall not point to any element in the range [first,last).

Return value

An iterator to the end of the destination range where elements have been copied.

Complexity

Linear in the distance between first and last: Performs an assignment operation for each element in the range.

Example

The following code uses copy to both copy the contents of one vector to another and to display the resulting vector:

#include <algorithm>
#include <iostream>
#include <vector>
#include <iterator>
#include <numeric> int main()
{
std::vector<int> from_vector();
std::iota(from_vector.begin(), from_vector.end(), ); std::vector<int> to_vector;
std::copy(from_vector.begin(), from_vector.end(),
std::back_inserter(to_vector));
// or, alternatively,
// std::vector<int> to_vector(from_vector.size());
// std::copy(from_vector.begin(), from_vector.end(), to_vector.begin());
// either way is equivalent to
// std::vector<int> to_vector = from_vector; std::cout << "to_vector contains: "; std::copy(to_vector.begin(), to_vector.end(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';
}

Output:

to_vector contains: 0 1 2 3 4 5 6 7 8 9

std::copy使用方法的更多相关文章

  1. std::copy性能分析与memmove机器级实现

    复制数据的快速方法std::copy C++复制数据各种方法大家都会,很多时候我们都会用到std::copy这个STL函数,这个效率确实很不错,比我们一个一个元素复制或者用迭代器复制都来的要快很多. ...

  2. std::copy的使用

    看到有人在用std::copy这个东西,很简洁和爽啊,,所以找些帖子学习学习 http://blog.sina.com.cn/s/blog_8655aeca0100t6qe.html https:// ...

  3. 闲:测试memcpy和std::copy vector之间拷贝

    预测:底层C函数肯定比stl算法快 结果:少量数据底层快,大数据以上则stl对vector的处理可能更好 C/C++: #include <iostream> #include <v ...

  4. std::copy 和 std::back_inserter

    #define print_vector(v1) \ for(auto iter = v1.begin();iter != v1.end();iter++) \ cout<<*iter&l ...

  5. std::copy ( myvector.begin(), myvector.end(), out_it )

    在实际生产环境中,不能进行调试,所以程序通常需要编译一个DEBUG版本来辅助我们找出问题所在,编译这样的DEBUG版本最常用的手段就是在关键处输出我们关心一些变量的值到屏幕. 如果输出的简单的变量值, ...

  6. C++11 std::copy

    这个函数并不是简单的 while(first != last) { *result = *first; result++; first++; } 事实上这种写法是最具普适性的,值要求inputIter ...

  7. SVN:This client is too old to work with working copy…解决方法

    昨天升级了一下苹果系统到10.10,扁平化确实不错,高兴之余多少有些不快.我的svn出现故障,总是提示我  SVN:This client is too old to work with workin ...

  8. std::string 的方法c_str() 和 data() 有什么区别

    1.从C++标准上的解释来看,只有一点区别: c_str() 返回一个指向正规C字符串的指针常量,该指针保证指向一个 size() + 1 长度的空间,而且最后一个字符肯定是 \0 : 而 data( ...

  9. 从经典问题来看 Copy 方法(转)

    来自:Gua | 瓜地 链接:https://desgard.com/copy/  在初学 iOS 的时候,可能会被灌输这么一个常识,切记 NSString 的 property 的修饰变量要写作 c ...

随机推荐

  1. Java 8新增的日期、时间格式器

    一 获取DateTimeFormatter对象的三种方式 直接使用静态常量创建DateTimeFormatter格式器 使用代码不同风格的枚举值来创建DateTimeFormatter格式器 根据模式 ...

  2. DCloud-MUI:HBuilder 安装

    ylbtech-DCloud-MUI:HBuilder 安装 1.返回顶部 1. 2. 3. 4. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   7.返 ...

  3. kubernetes 学习 创建cronjob

    POM.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  4. C# DataTable的常用用法讲解

    在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...

  5. 第六章 Java并发容器和框架

    ConcurrentHashMap的实现原理与使用 ConcurrentHashMap是线程安全且高效的hashmap.本节让我们一起研究一下该容器是如何在保证线程安全的同时又能保证高效的操作. 为什 ...

  6. Linux 对mysql远程授权连接操作 和 查看mysql数据库和表 基本命令

    Linux 对mysql远程连接的授权操作 首先linux连接mysql数据库 授权: grant all on *.* to ' with grant option; //允许账户root从任何主机 ...

  7. java 多线程系列---JUC原子类(四)之AtomicReference原子类

    AtomicReference介绍和函数列表 AtomicReference是作用是对"对象"进行原子操作. AtomicReference函数列表   // 使用 null 初始 ...

  8. 12-22C#公共控件(基本功能)

    在C#窗体中,公共控件的基本功能: 1.获取.设置控件的参数值: 2.事件(其实是一种特殊的方法和属性,当被其他外力触发它,就会发生,类似数据库的触发器.) 下面是基本的公共控件: 1.复选框 1)设 ...

  9. xcode编译静态库选择cpu架构

    此前编译了一个静态库,默认支持了armv7,armv7s,arm64 编译的话肯定是上面三个静态库分别编译出来,然后在把这三个合并成一个单独的库. 如果单个库的大小是10M,那编译总的库大概就30M了 ...

  10. dubbo+zookeeper+dubboadmin环境搭建

    4.环境搭建 4.1.zookeeper注册中心的配置安装(在windows平台下,Linux类似,见官方文档)(Redis注册中心安装,简易注册中心安装,简易监控中心安装,见官方文档) 下载zook ...