All I want to do is to check whether an element exists in the vector or not, so I can deal with each case.
if ( item_present )
do_this();
else
do_that(
You can use the find function, found in the std
namespace, ie std::find
. You pass the std::find
function the begin
and end
iterator from the vector you want to search, along with the element you're looking for and compare the resulting iterator to the end of the vector to see if they match or not.
std::find(vector.begin(), vector.end(), item) != vector.end()
You're also able to dereference that iterator and use it as normal, like any other iterator.