是否有任何内置函数告诉我我的向量是否包含某个元素例如
Is there any built in function which tells me that my vector contains a certain element or not e.g.
std::vector<string> v;
v.push_back("abc");
v.push_back("xyz");
if (v.contains("abc")) // I am looking for one such feature, is there any
// such function or i need to loop through whole vector?
您可以使用 <代码>std::find如下:
You can use std::find
as follows:
if (std::find(v.begin(), v.end(), "abc") != v.end())
{
// Element in vector.
}
为了能够使用std::find
:include
.
这篇关于在 C++ 中检查是否 std::vector<string>包含一定的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!