Masinde70
3/23/2018 - 9:23 AM

find, find_if, find_if_not, find_first_of, search(looks for a sequence), search_n helps to find the consecutive sequences, adjacent_find

The algorithm to find something in the container to use cpp reference. find

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
  vector<int> v{2,4, 6, 6, 1, 3, -2, 0, 11, 2, 3, 2, 4, 4, 2, 4};
  string s{" Hello I am a string" };
  
  //Finding the first zero in the collection
  auto result = find(begin(v), end(v), 0);
  int weLookedFor = *result;
  
  //Find the first 2 after that zero
  result = find(result, end(v), 2);
  if (result != end(v)){
    weLookedFor = *result;
  }
  
  //Finding the first a
  auto letter = find(begin(s), end(s), 'a');
  char a = *letter;
  
  //Finding the odd value
  result = find_if(begin(v), end(v), [](auto elem){ return elem % 2 != 0});
}