可能重复:
How to find an item in a std::vector?如何在一个句子中检查std :: vector中元素的存在性?
这就是我在寻找:
#include <vector>
std::vector<int> foo() {
// to create and return a vector
return std::vector<int>();
}
void bar() {
if (foo().has(123)) { // it's not possible now, but how?
// do something
}
}
换句话说,我正在寻找一个短期和简单的语法验证向量中元素的存在。我不想为这个向量引入另一个临时变量。谢谢!
+1的P.S.,我从各种渠道上面的代码,但不知道包含头,因此我的代码是给错误。谢谢。 – 2015-01-24 20:25:27