可能重复:如何在std :: vector中查找项目?
嘿喜欢 Headers 建议我想检查矢量是否包含字符串“Key” . 我一直在寻找谷歌,我无法在矢量库中找到任何东西 . 任何人都可以帮助我 . 提前致谢 .
您可以使用std::find . 假设你有 std::vector 满 std::strings :
std::vector
std::strings
#include <algorithm> // for std::find std::vector<std::string> v = ....; std::vector<std::string>::const_iterator it = std::find(v.begin(), v.end(), "Key"); bool found = it != v.end();
1 回答
您可以使用std::find . 假设你有
std::vector
满std::strings
: