简体   繁体   中英

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. For example if I have a vector of int values

vector<int> V;

and I want to get all the elements that are greater than 5.

Thanks in advance.

You'd std::copy_if() if the values:

std::vector<int> target;
std::copy_if(v.begin(), v.end(), std::back_inserter(target),
             std::bind(std::less<int>(), 5, _1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM