Checking if v contains the element x:

#include

if(std::find(v.begin(), v.end(), x) != v.end()) {

/* v contains x */

} else {

/* v does not contain x */

}

Checking if v contains elements (is non-empty):

if(!v.empty()){

/* v is non-empty */

} else {

/* v is empty */

}

If searching for an element is important, I’d recommend std::set instead of std::vector. Using this:

std::find(vec.begin(), vec.end(), x) runs in O(n) time, but std::set has its own find() member (ie. myset.find(x)) which runs in O(log n) time – that’s much more efficient with large numbers of elements

std::set also guarantees all the added elements are unique, which saves you from having to do anything like if not contained then push_back()….