find_if c++ example
Example: find_if c++ example
#include
#include
#include
using namespace std;
int main()
{
vector myvec {2, 5, 6, 10, 56, 7, 48, 89};
vector::iterator gt10 = find_if(myvec.begin(), myvec.end(), [](int x){return x>10;}); // >= C++11
cout << "First item > 10: " << *gt10 << endl;
//check if pointer points to myvec.end()
if(gt10 != myvec.end()) {
cout << "nf points to: " << *gt10 << endl;
}
else {
cout << "item not found" << endl;
}
return 0;
}