我找到所有的单词,有五个字母在一个向量的字符串与equal_range,它一直抛出一个错误,说它没有排序
i am finding all words that have five letters in a vector of strings with equal_range and it keeps throwing an error saying it isnt sorted
void Iterator::displayStringFour(const vector<string> &v)
{
vector<string>tempVect(v.size());
tempVect = v;
int smallest;
sort(tempVect.begin(), tempVect.end(), Equal());
在上面的行中,我按照字符串中字符从最小到最大的顺序对向量进行排序。
pair<vector<string>::iterator,vector<string>::iterator> equalRange;
*下一行抛出错误,表示集合不是排序。我用过一个函数函数对象,按照字符从最小到最大的顺序排序,我不确定我还会怎么排序向量*
equalRange = equal_range(tempVect.begin(),tempVect.end(),"-----");
vector<string>::iterator range = equalRange.first;
while(range!=equalRange.second)
{
cout<<*range;
++range;
}
}
这是我的函数函数对象,它接受两个字符串并对vector
进行排序
class Equal
{
public:
bool operator()(string a,string b)
{
return a.length()<b.length();
}
};
将Equal()传递给equal_range作为第四个参数,否则它将使用默认的比较函子,即'less'。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '