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()函数
stl中copy()函数_std :: copy()函数以及C ++ STL中的示例相关推荐
- stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例
stl中copy()函数 C ++ STL std :: rotate_copy()函数 (C++ STL std::rotate_copy() function) rotate_copy() fun ...
- stl min函数_std :: min()函数以及C ++ STL中的示例
stl min函数 C ++ STL std :: min()函数 (C++ STL std::min() function) min() function is a library function ...
- stl max函数_std :: max_element()函数以及C ++ STL中的示例
stl max函数 C ++ STL std :: max_element()函数 (C++ STL std::max_element() function) max_element() functi ...
- matlab中copy函数,Matlab 的函数
              预备知识 Matlab 的判断与循环 函数文件 我们已经学了 ...
- Golang——切片使用大全(创建、初始化、遍历、截取、修改、添加、切片的copy、切片作为函数参数、切片求和、切片求最大值)
概念: 切片出现的原因也是因为数组的可操作性不高.切片的长度是不固定的,可以追加数据,可以理解切片是一个动态数组,切片的底层是一个结构体 切片类型(slice)本身并不是动态数组或数组指针.它内部通过 ...
- python拷贝文件函数_python笔记2小数据池,深浅copy,文件操作及函数初级
小数据池就是在内存中已经开辟了一些特定的数据,经一些变量名直接指向这个内存,多个变量间公用一个内存的数据. int: -5 ~ 256 范围之内 str: 满足一定得规则的字符串. 小数据池: 1,节 ...
- R语言使用fs包的file_copy函数、dir_copy函数、link_copy函数将文件、目录、超链接从一个位置拷贝(copy)到另一个位置
R语言使用fs包的file_copy函数.dir_copy函数.link_copy函数将文件.目录.超链接从一个位置拷贝(copy)到另一个位置 目录
- c++stl和std_std :: replace()函数以及C ++ STL中的示例
c++stl和std C ++ STL std :: replace()函数 (C++ STL std::replace() function) replace() function is a lib ...
- c++中STL的常用算法--1(函数对象,谓词,内建函数对象)
函数对象 重载函数调用操作符的类,其对象常称为函数对象(function object),即它们是行为类似函数的对象,也叫仿函数(functor),其实就是重载"()"操作符,使得 ...
最新文章
- python音频聚类_Python实现聚类算法AP
- 预防鼻炎以及空气污染对策
- @ConfigurationProperties使用时几个常见误区
- 【qduoj - 纳新题】小明的dp(快速幂 + 乘法原理)(简单组合数学)
- input 输入事件_输入超时为例学习 Python 的线程和协程
- 周华健,歌声伴我成长(三)
- nginx部署两个php虚拟主机,nginx服务器,fastcgi模式,添加虚拟主机(多站点)配置...
- Redis开发与运维之第八章理解内存(四)
- 清风老师数学建模笔记——层次分析法
- ros_arduino_bridge功能包集的使用
- 冰点还原界面无法呼出如何解决
- 什么是私有云、公有云、混合云?什么是云计算管理平台?
- Python之selenium进阶
- 淘宝修改密码可能引发手机骚扰
- 再读《终身成长》——重塑思维
- 虚拟机canal-deployer连接主机mysql失败
- Mybatisplus lambda写法随笔
- 计算机网络ospf实验报告,计算机网络实验报告12_ospf实验
- 报错: chaser.rb:35 in `join': No live threads left.
- asyncio的正确使用姿势
热门文章
- php js 比较,PHP与JS的比较
- python可以做特效吗_学习mel语言,Python,JavaScript到什么程度才能做一下大型特效,要自已开发插件脚本呢?...
- sql中in与php数组,格式化SQL“IN”子句的PHP数组
- java安全(三)RMI
- 基于GET报错的sql注入,sqli-lab 1~4
- linux 编译3g驱动_linux重新编译内核
- java 监听窗口是否改变_JAVA项目监听文件是否发生变化
- 获取Linux内存、cpu、磁盘IO等信息
- Linux namespace之:uts namespace
- Hadoop之HDFS应用