# include
using namespace std;
#include
#include
//time系统时间头文件包含
# include
# include
//1.设计英雄结构体
struct hero
{
string name;
int age;
string gender;
};
void sort(struct hero heroArray,int len)
{
for(int j=0;j-1;j++)
{
for(int k=0;k-1;k++)
{
if(heroArray[k].age>heroArray[k+1].age)
{
struct hero temp=heroArray[k];
heroArray[k]=heroArray[k+1];
heroArray[k+1]=temp;
}
}
}
}
void printhero(struct hero heroArray[],len){
for(int g=0;g"姓名:"<"年龄:"<"gender"<int main(){
//2.创建数组存放英雄
struct hero heroArray[5]=
{
{"JYC",18,"男"},
{"JJJ",16,"女"} ,
{"a",12,"girl"} ,
{"b",133,"man"},
{"c",12,"man"},
};
int len=sizeof(heroArray)/sizeof(heroArray[0]);
// for(int i=0;i
// cout<<"姓名"<
// <<" 年龄:"<
// <<" gender:" <
// }
//3.对数组进行排序,按照年龄进行输出
sort(heroArray,len);
//4.将排序后的结构打印出
pringinf(heroArray,len);
return 0;
}
想问一下为什么在定义SORT函数的时候显示 [Error] no match for 'operator[]' (operand types are 'hero' and 'int')啊?
sort函数的hero后面加个*,应该是指针类型。或者和打印函数一样后面加中括号