博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stl中copy()函数_std :: copy()函数以及C ++ STL中的示例
阅读量:2529 次
发布时间:2019-05-11

本文共 2248 字,大约阅读时间需要 7 分钟。

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
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 
#include
#include
using namespace std;int main(){
//declaring & initializing an int array int arr[] = {
10, 20, 30, 40, 50 }; //vector declaration vector
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 50v1: 10 20 30 40 50

Reference:

参考:

翻译自:

stl中copy()函数

转载地址:http://vttzd.baihongyu.com/

你可能感兴趣的文章
su 与 su - 区别
查看>>
C语言编程-9_4 字符统计
查看>>
在webconfig中写好连接后,在程序中如何调用?
查看>>
限制用户不能删除SharePoint列表中的条目(项目)
查看>>
【Linux网络编程】使用GDB调试程序
查看>>
feign调用spring clound eureka 注册中心服务
查看>>
ZT:Linux上安装JDK,最准确
查看>>
LimeJS指南3
查看>>
关于C++ const成员的一些细节
查看>>
《代码大全》学习摘要(五)软件构建中的设计(下)
查看>>
C#检测驱动是否安装的问题
查看>>
web-4. 装饰页面的图像
查看>>
微信测试账户
查看>>
Android ListView上拉获取下一页
查看>>
算法练习题
查看>>
学习使用Django一 安装虚拟环境
查看>>
Hibernate视频学习笔记(8)Lazy策略
查看>>
CSS3 结构性伪类选择器(1)
查看>>
IOS 杂笔-14(被人遗忘的owner)
查看>>
自动测试用工具
查看>>