int cmp(stu x,stu y)
{
if(x.count==y.count)
{
int t3=strcmp(x.str,y.str);
if(t3>0)
return 0;
return 1;
}
return x.count>y.count;
}
中的int t3=strcmp(x.str,y.str);会报错为什么?
怎么解决?原因是什么?
你的str什么类型?string?直接用==就可以
用strcmp要先用c_str()得到其中的字符数组指针
strcmp函数原型为int strcmp(const char * string1,const char * string2),所以首先你的实参数类型需要是字符串的地址,看看你的实参类型符合吗?
strcmp函数原型为int strcmp(const char * string1,const char * string2),所以首先你的实参数类型需要是字符串的地址,
不好意思网络卡了回复了这么多。其次你可以进行单步调试看看是哪一句的问题,
错误提示已经明确说明了不能将string 转换为const char *, 要么使用string 数据直接比较,要么把string类型转换为char *(使用c_str()函数)