Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;排序不';不要使用自定义函数_C++_Sorting_Vector_Comparator_Stl Algorithm - Fatal编程技术网

C++ c++;排序不';不要使用自定义函数

C++ c++;排序不';不要使用自定义函数,c++,sorting,vector,comparator,stl-algorithm,C++,Sorting,Vector,Comparator,Stl Algorithm,我在试着分类 std::vector< std::vector< std::string> > perm; 这是我的排序功能: bool sortPerms (const std::vector<std::string> &i, const std::vector<std::string> &j) { for(unsigned int x = 0; x < i.size(); x++) { if(i[x] !=

我在试着分类

std::vector< std::vector< std::string> > perm;
这是我的排序功能:

bool sortPerms (const std::vector<std::string> &i, const std::vector<std::string> &j) {
  for(unsigned int x = 0; x < i.size(); x++) {
    if(i[x] != j[x])
      return false;
  }
  //both are equal
  return true;
}
bool排序项(const std::vector&i,const std::vector&j){
for(无符号整数x=0;x
排序的目的是调用std::unique以获得具有唯一值的向量。 当我在cygwin中使用gcc编译时,我没有得到错误,但有重复,当我使用visual studio 2010编译时,我得到一个未定义运算符<的错误。 我已经介绍过了,它正在尝试使用自己的排序函数,而不是我定义的那个

我不知道如何解决这个问题,有什么建议吗

其他详情: 保证所有向量大小相同。 它的用途是字符串的原始向量的每个置换的向量。
每个字符串都是一个命令,我正在寻找所有不同的方法来洗牌这些命令。所以我需要去除重复项。

a
时,排序函数应该返回,而不是
a!=b


另外,默认情况下,
std::vector
应该已经通过
操作符支持字典比较当
a
而不是
a!=b


另外,默认情况下,
std::vector
应该已经支持通过
运算符进行字典比较,或者您可以指向出现错误的行吗?您希望如何仅基于不相等的概念对某个内容进行排序?这是一个声明,声明运算符<未定义。如果我提供了自己的comparatorI,我不确定为什么会出现这个问题,因为我没有看到提供的运算符,而是为std::sort()提供了一个回调函数。我猜在Windows上它使用了
LEFT
,其中
LEFT
在您的例子中是
std::vector
。您可能需要声明结构,其中包含一个
运算符
,并对其进行处理。@Grzegorz:为什么要使用派生自
std::vector
的新类型?只需要做一个自由的(“全局”)
运算符就可以了。请你指向出错的那一行,好吗?你希望如何仅仅根据不相等的概念对某个东西进行排序?这是一个声明,声明运算符<未定义。如果我提供了自己的comparatorI,我不确定为什么会出现这个问题,因为我没有看到提供的运算符,而是为std::sort()提供了一个回调函数。我猜在Windows上它使用了
LEFT
,其中
LEFT
在您的例子中是
std::vector
。您可能需要声明结构,其中包含一个
运算符
,并对其进行处理。@Grzegorz:为什么要使用派生自
std::vector
的新类型?只需制作一个免费的(“全球”)
operatorsweet,谢谢。我不确定vector是否有这样的函数,谢谢。此外,我认为abool sortPerms (const std::vector<std::string> &i, const std::vector<std::string> &j) {
  for(unsigned int x = 0; x < i.size(); x++) {
    if(i[x] != j[x])
      return false;
  }
  //both are equal
  return true;
}