[英]Get all stl vector elements greater than a value
I would like to know how can I find the list of a stl vector elements that have value verifying a certain condition. 我想知道如何找到具有验证特定条件价值的stl向量元素的列表。 For example if I have a vector of int values 例如,如果我有一个int值向量
vector<int> V;
and I want to get all the elements that are greater than 5. 我想获得大于5的所有元素。
Thanks in advance. 提前致谢。
You'd std::copy_if()
if the values: 如果满足以下条件,则可以使用std::copy_if()
:
std::vector<int> target;
std::copy_if(v.begin(), v.end(), std::back_inserter(target),
std::bind(std::less<int>(), 5, _1));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.