fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. bool is_1(int i){
  5. return i == 1;
  6. }
  7.  
  8. int main() {
  9. int ia[] = {13,2, 42, 32, 1, 4, 1};
  10.  
  11. auto pos = std::find_if(std::begin(ia), std::end(ia), is_1);
  12.  
  13. if (pos == std::end(ia)){
  14. std::cout << "Failed to find a 1\n";
  15. }
  16. else{
  17. std::cout << "Found a 1 at position " << (pos - std::begin(ia)) << '\n';
  18. }
  19. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Found a 1 at position 4