stl中copy()函数_std :: copy_if()函数以及C ++ STL中的示例
stl中copy()函数
C ++ STL std :: copy_if()函数 (C++ STL std::copy_if() function)
copy_if() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the certain elements (which satisfy the given condition) of a container from the given start position to another container from the given beginning position.
copy_if()函数是算法标头的库函数,用于复制容器的元素,它将容器的某些元素(满足给定条件)从给定的开始位置复制到另一个容器,从给定的开始位置位置。
Note:To use copy_if() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.
注意:要使用copy_if()函数 –包括<algorithm>头文件,或者您可以简单地使用<bits / stdc ++。h>头文件。
Syntax of std::copy_if() function
std :: copy_if()函数的语法
std::copy_n(
iterator source_first,
iterator source_end,
iterator target_start,
UnaryPredicate pred);
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 –是目标容器的开始迭代器。
UnaryPredicate pred – Unary function which accepts an element in the range as an argument, and returns a value convertible to bool.
UnaryPredicate pred –一元函数,该函数接受范围内的元素作为参数,并返回可转换为bool的值。
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 5 array elements to the vector
copy_n(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_if()函数的使用 (C++ STL program to demonstrate use of std::copy_if() function)
In this example, we are copying only positive elements of the array to the vector.
在此示例中,我们仅将数组的正元素复制到向量。
//C++ STL program to demonstrate use of
//std::copy_if() function
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{//declaring & initializing an int array
int arr[] = { 10, 20, 30, -10, -20, 40, 50 };
//vector declaration
vector<int> v1(7);
//copying 5 array elements to the vector
copy_if(arr, arr + 7, v1.begin(), [](int i) { return (i >= 0); });
//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 -10 -20 40 50
v1: 10 20 30 40 50 0 0
Reference: C++ std::copy_if()
参考: C ++ std :: copy_if()
翻译自: https://www.includehelp.com/stl/std-copy_if-function-with-example.aspx
stl中copy()函数
stl中copy()函数_std :: copy_if()函数以及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中copy()函数_std :: copy()函数以及C ++ STL中的示例
stl中copy()函数 C ++ STL std :: copy()函数 (C++ STL std::copy() function) copy() function is a library fu ...
- 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 ...
- 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),其实就是重载"()"操作符,使得 ...
- c++stl和std_std :: rotate()函数以及C ++ STL中的示例
c++stl和std C ++ STL std :: rotate()函数 (C++ STL std::rotate() function) rotate() function is a librar ...
- matlab中copy函数,Matlab 的函数
              预备知识 Matlab 的判断与循环 函数文件 我们已经学了 ...
- Dictionary作为数据源绑定,调用c++库中返回为BYTE*的函数,listView项排序
最近在做一个电子档案管理的项目.现在还处于初期,只是做一个简单demo拿去跟客户演示.至于最后谈不谈得下来,到底做不做,反正我是不看好,但没因为这样就马马虎虎.草草了事.这个项目算是b/s加c/s混合 ...
最新文章
- 太原未来小使者英语大赛_哥伦比亚2020年中学生“汉语桥”大赛成功在线举办...
- 数据结构Java06【赫夫曼树、概述、原理分析、代码实现(数据压缩、创建编码表、解码、压缩文件、解压文件)】
- 1、如何理解SQL Server的实例
- mysql无法启动如何备份文件_mysql 5.7 停电导致无法启动、如何备份数据,重新安装mysql...
- 刚刚开通博客,分享Asp.Net的GridView的基本用法
- 【Antlr】Antlr 在语法中嵌入任意动作
- 校招刷题---java选择题笔记04
- (转)Visual C++开发工具与调试技巧整理
- 转行经验分享,关于软件测试的感悟,你想知道的都在这里……
- 融跃品牌月:央视出手,各大卫视联合融跃助力金融学子成梦
- UE高级性能剖析技术(三)-- Android内存分布和优化
- 金三银四:蚂蚁金服JAVA后端面试题及答案之二面
- 高中3年,3500个词汇带音标,归成“图表”
- 针对Informer中时序数据ETT油温数据分析
- Android 预制第三方app到系统中
- 华为CCA汽车域控制器
- kafka-生产者消息发送流程
- ZOJ Yukari's Birthday
- Midjourney|文心一格prompt教程[Text Prompt(下篇)]:游戏、实物、人物、风景、动漫、邮票、海报等生成,终极模板教学
- EasyExcel导入和导出excel数据表格用法示例
热门文章
- 三年前端,面试思考(二)
- HTML引入vue.js,在ie浏览器中不显示
- Codeforces Round #556 (Div. 1)
- 搭建springboot环境
- 动态规划:从新手到专家
- 【SQL】服务器环境下的SQL
- 通过setTimeout来取消因大量计算造成的网页卡顿
- echo 12345678 | base64 产生的结果跟12345678真正的base64编码不对
- zk中的Datebox中得到Timestamp
- SQL Server 2000数据库移植到SQL Server 2008R2数据库服务器中碰到的”3145错误”及解决办法...