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; }是正确的
相关文章推荐
- 《编写一个方法,返回第二个参数在第一个参数中出现次数——C#第五周》
- c#--编写一个名称为MyClass一个类,在该类中编写一个方法,名称为CountChar,返回值为整型,参数两个,第一个参数可以是字符串、整数、单精度、双精度,第二个参数为字符,方法功能返回第二个参
- String作为函数参数时,传入的是值,不是地址
- 解决三星手机post请求时参数包括集合,封装成JSONObject,结果不是数组而是数组的地址问题
- 数组作为参数传递,是地址的传递,不是值传递。
- C#--第六周实验--任务1--返回第二个参数在第一个参数中出现次数
- Loadrunner 出现第一个迭代运行正常,第二个迭代出现错误,参数找不到等等,可能是勾选了“在每个迭代模拟一个新用户”
- Android-ndk-r8e wordlist 第二个参数不是数值参数
- 有三个参数的函数,一个为字符,两个为整数,第二个整数代表行数,第一个整数代表每行的字符的个数
- BitmapFactory.decodeResource(res, id); 第一个参数跟第二个参数有什么关系?
- C#程序设计(十五)----返回第二个参数在第一个参数中出现次数/参数的逆序
- 写一个 function,它遍历一个对象数组(第一个参数)并返回一个包含相匹配的属性-值对(第二个参数)的所有对象的数组。
- 文件操作函数fseek设置文件指针的位置,第三个参数是起始地址,有0,1,2三个值,分别指首地址,当前地址,文件尾地址EOF;第二个参数是偏移地址正为右,负为左
- Linux 之sort-多关键字排序(在第一个关键字的基础上再进行第二个关键字排序)
- PHP 分页获取数据 三个参数 ( 第一个参数获取页数,第二个条件 ,第三个数据为id降序desc或者升序asc)
- C语言数组元素地址作为函数参数
- 编写一个函数 接受两个字符串参数 如果 第一个参数被第二个包含 则输出第一个参数的首字符(图)
- 浅谈 memset 函数的第二个参数为什么是 int 而不是 char
- $()是有两个参数,第一个是选择器,第二个是作用域
- c#返回第二个参数在第一个参数中出现次数