簡體   English   中英

獲取所有大於值的stl向量元素

[英]Get all stl vector elements greater than a value

我想知道如何找到具有驗證特定條件價值的stl向量元素的列表。 例如,如果我有一個int值向量

vector<int> V;

我想獲得大於5的所有元素。

提前致謝。

如果滿足以下條件,則可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM