Answers for "find function in array in c++"

C++
5

vector.find()

#include <algorithm>
#include <vector>

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
   do_this();
else
   do_that();
Posted by: Guest on July-09-2020
0

C++ array find method

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

int main() {
    array<int, 5> arrayfind{ 3,4,1,2,5 };
    int Finding = 2;//an element to find
    bool Founded;

    Founded = binary_search(arrayfind.begin(), arrayfind.end(), Finding);
    //if the element that you're looking for is in the array,
    //bool Founded will be true
    if (Founded == true) {
        cout << Finding << " Is in the array!";
    }
    else {
        cout << Finding << " Is not in the array!";
    }
}
Posted by: Guest on August-09-2021

Code answers related to "find function in array in c++"

Browse Popular Code Answers by Language