c++ 结构体 初始化
#include <iostream>
#include <algorithm>
#include<cstring>
using namespace std;
struct student{
int grade;
char name[101]{};
int age;
student(){};
student(int Grade , const char Name[], int Age){
this->grade=Grade;
strcpy(this->name, Name);
this->age=Age;
}
};
int main(){
student stu1={100,"lucy",16};
cout<<stu1.grade<<" "<<stu1.name<<" "<<stu1.age<<" "<<endl;
student stu2(98,"frank",15);
cout<<stu2.grade<<" "<<stu2.name<<" "<<stu2.age<<" "<<endl;
int n=2;
student people[n];
for (int i = 0; i <n ; ++i) {
scanf("%d%s%d",&people[i].grade,people[i].name,&people[i].age);
}
for (int i = 0; i < n;i++){
cout<<people[i].grade<<" "<<people[i].name<<" "<<people[i].age<<" "<<endl;
}
return 0;
}