(c++ std) 查找 vector 中的元素

You can use std::find from <algorithm>:

std::find(vector.begin(), vector.end(), item) != vector.end()

This returns a bool (true if present, false otherwise). With your example:

#include <algorithm>

if ( std::find(vector.begin(), vector.end(), item) != vector.end() )
   do_this();
else
   do_that();
原文地址:https://www.cnblogs.com/liujx2019/p/10553085.html