C++ 已命名的返回值不再受支持。错误
使用下面的代码,我得到以下错误: 不再支持命名返回值返回a.mark>b.mark 有人能帮我诊断这个错误吗C++ 已命名的返回值不再受支持。错误,c++,sorting,structure,C++,Sorting,Structure,使用下面的代码,我得到以下错误: 不再支持命名返回值返回a.mark>b.mark 有人能帮我诊断这个错误吗 #include<bits/stdc++.h> using namespace std; struct student { public: string name; int rank; int mark; student() { mark=0; } }; bool compare(student a
#include<bits/stdc++.h>
using namespace std;
struct student
{
public:
string name;
int rank;
int mark;
student()
{
mark=0;
}
};
bool compare(student a,student b)
return a.mark>b.mark;
int main()
{
int n;
cin>>n;
string*input=new string[n];
student s[n];
for(int i=0;i<n;i++)
{
getline(cin,input[i]);
}
//string *name=new string[n];
//int *nums=new int[n];
// int *next_nums_pos=new int[n];
for(int i=0;i<n;i++)
{
int j=0;
int count=0;
int start=0;
//nums[i]=new int[100];
//next_nums_pos[i]=0;
//nums[i]=0;
int size=0;
while(input[i][j]!='\0')
{
if(count==0)
{
if(input[i][j]==' ')
{
s[i].name=input[i].substr(start,size);
//cout<<name[i]<<endl;
start=j+1;
count++;
size=0;
}
else
size++;
}
else
{
if(input[i][j]==' ')
{
int m;
stringstream mark(input[i].substr(start,size));
mark>>m;
s[i].mark+=m;
start=j+1;
size=0;
}
else
size++;
}
j++;
}
int m;
stringstream mark(input[i].substr(start,size));
mark>>m;
s[i].mark+=m;
}
sort(s,s+n,compare);
for(int i=0;i<n;i++)
{
cout<<i+1<<" "<<s[i].name;
}
//cout<<name[0]<<endl;
//for(int i=0;i<n;i++)
// cout<<name[i]<<endl;
return 0;
}
#包括
使用名称空间std;
结构学生
{
公众:
字符串名;
整数秩;
整数标记;
学生()
{
分数=0;
}
};
布尔比较(学生a、学生b)
返回a.mark>b.mark;
int main()
{
int n;
cin>>n;
字符串*输入=新字符串[n];
学生s[n];
对于(int i=0;ii,我添加了{},它得到了修复:
bool compare(student a,student b){
return a.mark>b.mark;
}
您必须使用{}对于函数,我们可以更好地阅读和理解您的代码,您永远不会看到此类错误。将自己置于第一次阅读此代码的人的位置,尝试想象正在发生的事情。与大多数编程问题一样,您应该尝试使用尽可能少的代码重新创建问题,直到隔离出问题所在问题是,你的问题格式化质量很差,这篇文章应该帮助你:然后你可以把重点放在什么地方,或者请求别人帮助你。答案不是你得到正确答案吗?如果是,考虑一下。