我希望使用set来去重并保持顺序。因此,我尝试更改比较参数,使它们按照插入顺序排序。
#include <set>
#include <iostream>
using namespace std;
template <class T>
struct compare
{
bool operator() (T x, T y)
{
return true;
}
};
void main()
{
set<int,compare<int>> one;
one.insert(5);
one.insert(3);
one.insert(9);
one.insert(1);
one.insert(5);
one.insert(5);
}
IDE中的表达式是:无效操作符<。
std::set
已经对其项进行排序并且不包含重复项。你不需要在任何这些问题上“帮助”集合。所以我猜set
不是你应该使用的容器。 - PaulMcKenziestd::set
需要一个简单的弱排序。插入顺序并不能满足这个条件。你的比较器也不行。 - juanchopanza