If I run the following code, I get the error as prog.cpp:7:39: error: no match for ‘operator==’ (operand types are ‘bool’ and ‘std::vector::iterator {aka __gnu_cxx::__normal_iterator<int, std::vector >}’) if(binary_search(v.begin(),v.end(),3) == v.end()) cout<<"not found";*
But if I use find() instead of binary_search() I get the result as expected. Both these functions return an iterator only, But why are they acting differently in this situation?
#include <bits/stdc++.h>
using namespace std;
int main ()
{
vector < int >v = { 1, 2, 3, 5 };
if (binary_search (v.begin (), v.end (), 3) == v.end ())
cout << "not found";
else
cout << "found";
}