(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();
浙公网安备 33010602011771号