有的是std::find()
算法,它在迭代器范围内执行线性搜索,例如,
std::vector<int> v;
// Finds the first element in the vector that has the value 42:
// If there is no such value, it == v.end()
std::vector<int>::const_iterator it = std::find(v.begin(), v.end(), 42);
如果你的向量已排序,你可以使用std::binary_search()
测试向量中是否存在某个值,以及std::equal_range()
获取向量中具有该值的元素范围的开始和结束迭代器。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)