Answers for "vector find"

11

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 */
}
Posted by: Guest on January-17-2020
5

vector.find()

#include <algorithm>
#include <vector>

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
   do_this();
else
   do_that();
Posted by: Guest on July-09-2020
2

c++ find element in vector

auto it = find(vec.begin(),vec,end(), item)!
if(it != vec.end()){
 	 int index = it - vec.begin();
}
Posted by: Guest on December-03-2020
0

vector find

auto it = find(vec.begin(),vec,end(), item)!
Posted by: Guest on June-04-2021

Browse Popular Code Answers by Language