if vector contains value c++
#include <algorithm> if(std::find(v.begin(), v.end(), x) != v.end()) { /* v contains x */ } else { /* v does not contain x */ }
check if an item is in a vector c++
bool Movies::add_movie(std::string name, std::string rating, int watched) { Movie pass(name,rating,watched); for(int i{0}; i < movies.size(); i++){ if(movies.at(i).get_name() == name){ return false; } } movies.push_back(pass); return true; }