您的位置:首页 > 其它

error:sort()的第一个第二个参数是地址,而不是数组元素

2014-02-18 21:18 246 查看
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student
{
	string name;
	int age,score;
};
bool cmp(student s1,student s2)
{
		return s1.score<s2.score;
}

int main()
{
	student st[4];
	for(int h=0;h<4;h++)
	{
		cin>>st[h].name>>st[h].age>>st[h].score;
	}
	sort(st[0],st[4],cmp);
	return 0;
}
是错误的。
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student
{
	string name;
	int age,score;
};
bool cmp(student s1,student s2)
{
		return s1.score<s2.score;
}

int main()
{
	student st[4];
	for(int h=0;h<4;h++)
	{
		cin>>st[h].name>>st[h].age>>st[h].score;
	}
	sort(st,st+4,cmp);
	return 0;
}
是正确的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐