C++是唯一的,并且设置不起作用
C++ unique and set not working
unique不起作用,请提供帮助其显示的编译器错误
我试着把它做成
set<str> se(ss.begin(), ss.end());
ss.assign(se.begin(), se.end());
我也试过了,它还显示了编译器错误
是因为bool sortByString()
吗
我在一个页面上看到了这段代码,它有助于对向量类对象进行排序如果有其他方法,请帮助
#include <cmath>
#include<set>
#include <cstdio>
#include <vector>
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
int n;
class str
{
public:
string a;
void in(string s)
{
a=s;
}
string get(){
return a;
}
void out()
{
cout<<a;
}
};
bool sortByString(str &t1, str &t2)
{
return t1.get() < t2.get();
}
string d(vector<str> a)
{
string s;
for(int i=0;i<n;i++)
s.append(a[i].get());
return s;
}
int main() {
string s,sub;
cin >> s;
int length = s.length();
int i, k = 0, c;
vector<str> ss;
str a;
n = length*((length + 1) / 2);
k = 0;
for (c = 0; c < length; c++)
{
for (i =length-c;i>=1; i--)
{
a.in(s.substr(c,i));
ss.push_back(a);
}
}
s=" ";
ss.erase(unique(ss.begin(),ss.end()),ss.end()); /*code giving compiler error pls help*/
s=d(ss);
cout<<s;
return 0;
}
您在str.std:中缺少operator==
:unique需要此运算符。
class str
{
//....
bool operator==(const str& rop) const {
return a == rop.a;
}
};
bool sortByString(str &t1, str &t2)
bool sortByString(const str &t1, const str &t2)
至少对于g++。我想VS会编译任何一个。
相关文章:
- C++ Visual Studio Code 的设置不起作用
- Clang Tidy 插件 for Visual Studio Code 不起作用/如何设置
- 在qt QFileDialog中设置后缀在linux中不起作用,如何解决?
- 将复制构造函数设置为默认值在继承自 QObject 时不起作用
- glTexImage2D 不起作用,但将 FragColor 设置为 vec4(1.0, 0, 0, 1.0) 会给我红色图像
- 将字符数组设置为彼此相等的方法不起作用
- 设置c 代码示例,带有sqlite3不起作用
- setSockopt在C 中不起作用(超时设置为1s,等待更长的时间)
- 我无法正确获取这些变量声明...为什么这些参数不起作用?我只是将 n 值设置为数组长度
- 101 Qt 样式表边距填充黑客指南在C++。设置填充不起作用
- Mac OS X 中的设置区域设置不起作用
- 设置交叉点不起作用
- std::在C++中设置删除程序不起作用
- 在 c++ 中,如何远程设置注册表项(连接工作正常,但设置不起作用!
- 在 c++ 中设置函数不起作用
- 如何在OpenCV中设置相机的视频格式?CAP_PROP_FOURCC不起作用
- 设置固定 FPS 不起作用
- 设置图标不起作用
- 设置缩进宽度在咔嚓格式中不起作用
- C++是唯一的,并且设置不起作用