1. Making use of the std::count function
Counting the total number of items in the vector with the supplied value is the easiest solution. If the count is more than zero, we've discovered our element. Using the std::count function, this is simple.
#include
#include
#include
main int ()
{
v = 4, 7, 5, 2, 6, 9; std::vector v = 4, 7, 5, 2, 6, 9;
int key = 6; int key = 6; int key = 6; in
if (v.begin(), v.end(), key) (std::count(v.begin(), v.end(), key) {
"Element discovered"; std::cout
}
otherwise
"Element not found"; std::cout
}
0 is returned;
}