vector.find() 1

vector.find()

#include 
#include 

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
   do_this();
else
   do_that();

Here is what the above code is Doing:
1. The std::find function is a generic algorithm that searches for a value in a range.
2. The first two arguments to std::find are the beginning and end of the range to search.
3. The third argument is the value to search for.
4. The return value of std::find is an iterator to the found value, or the end of the range if the value was not found.
5. The != operator compares iterators, and returns true if they do not point to the same element.
6. The if statement checks if the value was found.

Similar Posts