stl中copy()函数_std :: copy()函数以及C ++ STL中的示例

stl中copy()函数

C ++ STL std :: copy()函数 (C++ STL std::copy() function)

copy() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the elements of a container from given range to another container from a given beginning position.

copy()函数算法标头的库函数,用于复制容器的元素,它将容器的元素从给定范围复制到给定起始位置的另一个容器。

Note:To use copy() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.

注意:要使用copy()函数 –包括<algorithm>头文件,或者您可以简单地使用<bits / stdc ++。h>头文件。

Syntax of std::copy() function

std :: copy()函数的语法

    std::copy(iterator source_first, iterator source_end, iterator target_start);

Parameter(s):

参数:

  • iterator source_first, iterator source_end – are the iterator positions of the source container.

    迭代器source_first,迭代器source_end –是源容器的迭代器位置。

  • iterator target_start – is the beginning iterator of the target container.

    迭代器target_start –是目标容器的开始迭代器。

Return value: iterator – it is an iterator to the end of the target range where elements have been copied.

返回值: 迭代器 –它是目标元素已复制到目标范围末尾的迭代器。

Example:

例:

    Input:
//declaring & initializing an int array
int arr[] = { 10, 20, 30, 40, 50 };
//vector declaration
vector<int> v1(5);
//copying array elements to the vector
copy(arr, arr + 5, v1.begin());
Output:
//if we print the value
arr: 10 20 30 40 50
v1: 10 20 30 40 50

C ++ STL程序演示了std :: copy()函数的使用 (C++ STL program to demonstrate use of std::copy() function)

In this example, we are copying the array elements to the vector.

在此示例中,我们将数组元素复制到向量。

//C++ STL program to demonstrate use of
//std::copy() function
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
//declaring & initializing an int array
int arr[] = { 10, 20, 30, 40, 50 };
//vector declaration
vector<int> v1(5);
//copying array elements to the vector
copy(arr, arr + 5, v1.begin());
//printing array
cout << "arr: ";
for (int x : arr)
cout << x << " ";
cout << endl;
//printing vector
cout << "v1: ";
for (int x : v1)
cout << x << " ";
cout << endl;
return 0;
}

Output

输出量

arr: 10 20 30 40 50
v1: 10 20 30 40 50

Reference: C++ std::copy()

参考: C ++ std :: copy()

翻译自: https://www.includehelp.com/stl/std-copy-function-with-example.aspx

stl中copy()函数

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541094.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

phpmyadmin管理mysql_用phpMyAdmin管理MySQL数据库_MySQL

phpmyadmin学会使用基于Web数据库的管理工具phpMyAdmin。如果使用合适的工具&#xff0c;MySQL数据库的管理就会为得相当简单。应用MySQL命令行方式需要对MySQL知识非常熟悉&#xff0c;对SQL语言也是同样的道理。不仅如此&#xff0c;如果数据库的访问量很大&#xff0c;列表中…

Linux网络那点事

跨平台系列汇总&#xff1a;http://www.cnblogs.com/dunitian/p/4822808.html#linux 之前的之前说过网络自连接的配置&#xff08;CentOS服务器网络配置&#xff1a;http://www.cnblogs.com/dunitian/p/4975830.html&#xff09;&#xff0c;这次和这个类似 这种方法适用于Cent…

机器学习中的马尔可夫随机场模型

马尔可夫随机场 (Markovs Random Fields) Markov random model is a model which use an undirected graph. Undirected graphical models edge represents the potential between two variables, syntactically, Factorization distribution probabilities between variable. …

python爬虫反爬 css 知乎 专栏_反反爬虫系列(四)

过完年&#xff0c;好了&#xff0c;咱们接着更新反反爬虫系列至于之前有朋友表示出一下1688呀&#xff0c;x宝的反反爬虫说实在的&#xff0c;阿里系的反爬虫很厉害&#xff0c;我自愧不能搞定。比如x宝的登录&#xff0c;用了selenium chrome的朋友都会遇到滑条拖动验证失败…

javaweb中mysql数据库的回滚操作代码

2019独角兽企业重金招聘Python工程师标准>>> 在mysql中创建用户账户数据库&#xff08;注意&#xff0c;count不能为负数&#xff0c;要设置无符号型&#xff09; 添加数据 下面我们得到connection对象开始进行事务提交和回滚的操作 package com.lyb.test; import s…

ruby array_Ruby中带有示例的Array.shuffle方法

ruby arrayArray.shuffle方法 (Array.shuffle Method) In this article, we will study about Array.shuffle method. You all must be thinking the method must be doing something which is related to shuffling of elements or objects in the Array instance. It is not …

【147天】尚学堂高淇Java300集视频精华笔记(108-109)

第108集:容器equals和hashcodeJDK源代码分析 本集知识点 Java中规定&#xff0c;若两个对象equals比较后内容相等&#xff08;为true&#xff09;&#xff0c;则hashCode必须相等&#xff0c;反之不然。【原因见内存分析图】hashCode与equals方法必须同时重写&#xff0c;且必须…

ruby hash方法_Ruby中带有示例的Hash.key?(obj)方法

ruby hash方法Hash.key&#xff1f;(obj)方法 (Hash.key?(obj) Method) In this article, we will study about Hash.key?(obj) Method. The working of the method cant be assumed because of its quite a different name. Let us read its definition and understand its …

python迭代器与生成器答案_史上最全 Python 迭代器与生成器

原标题&#xff1a;史上最全 Python 迭代器与生成器作者&#xff1a;浪子燕青链接&#xff1a;http://www.langzi.fun/迭代器与生成器.html迭代器与可迭代对象概念迭代器&#xff1a;是访问数据集合内元素的一种方式&#xff0c;一般用来遍历数据&#xff0c;但是他不能像列表一…

[性能测试] LoadRunner结果分析 – TPS

本文转载自&#xff1a;http://www.tuicool.com/articles/6z6vuy针对吞吐率和 TPS 的关系&#xff0c;这个在结果分析中如何使用&#xff0c;就个人经验和朋友讨论后&#xff0c;提出如下建议指导&#xff0c;欢迎同僚指正。相关定义响应时间 网络响应时间 应用程序响应时间响…

密码学电子书_密码学中的电子密码书(ECB)

密码学电子书This Electronic Code Book (ECB) is cryptography as a mode of operation for a block cipher, with the characters the main things that every feasible block of plaintext or an original text has a corresponding characteristic of ciphertext value and…

tsql是mysql中的吗_Mysql中的sql是如何执行的

MySQL中的SQL是如何执行的MySQL是典型的C/S架构,也就是Client/Server架构,服务器端程序使用的mysqld.整体的MySQL流程如下图所示:MySQL是有三层组成:连接层: 负责客户端与服务器端建立连接,客户端发送SQL至服务端;SQL层: 对SQL语句进行查询处理;存储引擎层: 与数据库文件打交道…

软件质量特性测试

针对软件质量特性进行测试&#xff0c;可以避免重大漏测&#xff0c;一般人我不告诉他。《软件工程—产品质量》&#xff08;GB/T 16260-2006&#xff09;中规定对软件的每个质量特性与子特性都有定义&#xff1a;一、功能性&#xff1a;是指当软件在指定条件下使用&#xff0c…

PHP array_pop()函数与示例

PHP array_pop()函数 (PHP array_pop() function) array_pop() function is used to delete/pop last element from the array. array_pop()函数用于从数组中删除/弹出最后一个元素。 Syntax: 句法&#xff1a; array_pop(array);Here, array is the input array, function w…

网站关停就没事了?5100万账户文件被盗

曾经是美国三大音乐视频文件共享软件之一的imesh&#xff0c;意外倒闭。而更意外的是&#xff0c;就在近日&#xff0c;imesh这款已经倒闭的软件&#xff0c;5100万账户开始在暗网被黑客拍卖。 Imesh这款软件是美国纽约的老牌音乐视频分享软件之一&#xff0c;早在2000年前便已…

数据库表设计索引外键设计_关于索引的设计决策 数据库管理系统

数据库表设计索引外键设计Introduction: 介绍&#xff1a; The attributes whose values are required inequality or range conditions and those that are keys or that participate in join conditions require access paths. 其值为必需的不等式或范围条件的属性以及作为键…

接口测试从零开始系列_mock技术使用

1、什么情况下会使用mock技术 &#xff08;1&#xff09;需要将当前被测单元和其依赖模块独立开来&#xff0c;构造一个独立的测试环境&#xff0c;不关注被测单元的依赖对象&#xff0c;只关注被测单元的功能逻辑 ----------比如被测代码中需要依赖第三方接口返回值进行逻辑处…

amie 规则挖掘_AMIE的完整形式是什么?

amie 规则挖掘AMIE&#xff1a;工程师协会的准会员 (AMIE: Associate Member of the Institution of Engineers) AMIE is an abbreviation of Associate Member of the Institution of Engineers. The Institution of Engineers India Limited (IEIL) provides this profession…

java 马克思_单链表-Java

public class SinglyListNode {int val;SinglyListNode next;SinglyListNode() {}SinglyListNode(int x) {this.val x;}}/*执行用时&#xff1a;12 ms, 在所有 Java 提交中击败了66.93%的用户内存消耗&#xff1a;39.5 MB, 在所有 Java 提交中击败了5.06%的用户*/class MyLink…

python的pass语句_Python | 演示pass语句的示例

python的pass语句python中的pass语句 (pass statement in python) "pass" is a type of null operation or null statement, when it executes nothing happens. It is used when you want do not want to write any code/statement to execute but syntactically a …