why did binary_search() false when u looking for 0
in vector stl
1 Like
please include the code you are considering
1 Like
vector v={10,20,30,0};
if(binary_search(v.begin(),v.end(),0))
cout<<“true”;
else
cout<<“false”;
out put is false
why i am getting false
the binary_search function requires that the vector is sorted
You can use “find” if that’s not the case
1 Like
thk
binary_search works on a sorted container