二进制“==”:没有运算符发现矢量 C++ 错误
binary '==' : no operator found error for vector C++
当我在 VS 2017 中编译我的 C++ 程序时,出现编译错误:binary'==':no operator found which takes a left-hand operand of type std::vector<int, std::allocator_Ty>
(或者没有可接受的转换)。
这是我第一次使用二维向量,我不确定这是否是部分原因。我的代码如下。谁能帮忙找出为什么会这样?
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> feeds;
void foo()
{
find(feeds.begin(), feeds.end(), feeds[0][0]);
}
您正在尝试将 int 与向量进行比较。
行 feeds.erase(find(feeds.begin(), feeds.end(), feeds[l][k]));
有两个向量迭代器(feeds.begin()
和 feeds.end()
),但 feeds[l][k]
指的是特定向量位置而不是向量。 feeds[l]
指的是矢量,应改为使用。
但是,当您已经知道要擦除哪个矢量 (feeds[l]
) 时,为什么还需要 find
。我建议你检查你的逻辑并从那里开始。
当我在 VS 2017 中编译我的 C++ 程序时,出现编译错误:binary'==':no operator found which takes a left-hand operand of type std::vector<int, std::allocator_Ty>
(或者没有可接受的转换)。
这是我第一次使用二维向量,我不确定这是否是部分原因。我的代码如下。谁能帮忙找出为什么会这样?
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> feeds;
void foo()
{
find(feeds.begin(), feeds.end(), feeds[0][0]);
}
您正在尝试将 int 与向量进行比较。
行 feeds.erase(find(feeds.begin(), feeds.end(), feeds[l][k]));
有两个向量迭代器(feeds.begin()
和 feeds.end()
),但 feeds[l][k]
指的是特定向量位置而不是向量。 feeds[l]
指的是矢量,应改为使用。
但是,当您已经知道要擦除哪个矢量 (feeds[l]
) 时,为什么还需要 find
。我建议你检查你的逻辑并从那里开始。