(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();
posted on 2019-03-18 16:46 liujx2019 阅读(25461) 评论(0) 编辑 收藏 举报