首页 文章

向量 . 检查它是否包含“密钥” . C [重复]

提问于
浏览
1

可能重复:如何在std :: vector中查找项目?

嘿喜欢 Headers 建议我想检查矢量是否包含字符串“Key” . 我一直在寻找谷歌,我无法在矢量库中找到任何东西 . 任何人都可以帮助我 . 提前致谢 .

1 回答

  • 4

    您可以使用std::find . 假设你有 std::vectorstd::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();
    

相关问题