查找向量的一个向量的元素是否存在于另一个向量中
Finding if elements of a vector of vector is present in another vector
我如何查看向量或向量列(ruleList)中的元素是否存在于另一个名为ntList的向量(不是向量向量)中。我目前有:
for(int j = 0; j < ruleList[0].size(); j++)
{
for(int i = 0; i < ntList.size(); i++)
{
if(std::find(ruleList[0][j].begin(), ruleList[0][j].end(), ntList[i]) != ruleList[0][j].end())
{
;
}
else
{
errorList.push_back(ERROR1);
error = true;
}
}
}
我收到一个错误,但我不完全确定为什么。
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'char' (or there is no acceptable conversion).
任何帮助将不胜感激。向量声明:
vector<string> ntList;
vector< vector<string> > ruleList(100, vector<string> (0, "0"));
根据你想要实现的目标,std::equal或(仅限C++11)std::is_permutation可能就足够了。如果您只想检查向量中是否存储了完全相同的值并且具有相同的大小,那么这些算法就足够了。
如果你想做更多的事情,例如将缺失值存储在其他地方,那么你最好使用手写循环。假设您在这两种情况下都处理 std::vector 并且不使用 C++11:
for (std::vector<int>::const_iterator iter_rule_list = ruleList[0].begin(); iter_rule_list != ruleList[0].end(); ++iter_rule_list)
{
int const value = *iter_rule_list;
if (std::find(ntList.begin(), ntList.end(), value) == ntList.end())
{
// value missing in ntList
}
}
相关文章:
- std::find,返回所有找到的值的替代方法,而不仅仅是存在重复的向量的第一个值
- 向量是否存在行主要形式?
- C++ 查找字符串中存在的元素向量
- 迭代时将指向differents类型的指针保存在std::向量中
- 在向量中存储字符串存在 SEG 错误
- C++ 如何检查另一个向量中是否存在矢量的内容
- 如何将向量一的所有元素与向量二进行比较,如果存在最大元素,则将向量二的所有元素与向量三进行比较?
- 从向量中擦除元素是否也会擦除元素中存在的所有成员向量
- 如何通过结构中的变量找出结构向量中是否存在结构
- 在C++中传递结构数组 - 被调用函数中不存在结构元素,如何正确传递向量?
- 在向量中查找值,而向量又存在于结构中
- 指向可能不存在的对象的指针向量
- 查找向量的一个向量的元素是否存在于另一个向量中
- 为什么 STL 向量的迭代器可以指向不存在的元素?
- 如何检查c++stl向量中是否存在值,并将函数应用于向量的每个元素
- 如果存在特定元素,则控制向量
- 如何确保向量中访问的索引存在
- 迭代和递归地查找向量中是否存在元素
- 检查向量中是否已经存在该值
- 是否可以将函数指针保存在std::向量中