Answers for "find_if c++ example"

C++
3

find_if c++ example

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  vector<int> myvec {2, 5, 6, 10, 56, 7, 48, 89};
  vector<int>::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;
}
Posted by: Guest on June-17-2020

Browse Popular Code Answers by Language