结构体输入
#include <iostream>
#include <string>
using namespace std;
struct student
{
int num;
int name[20];
int age;
char sex;
float score;
};
int main()
{
struct student stu[2];//创建一个结构体数组
for(int i = 0; i < 2; i++)//与数组操作一致
{
cin >> stu[i].num >> stu[i].name >> stu[i].age >> stu[i].sex >> stu[i].score;
}
for(int i = 0; i < 2; i++)
{
cout << stu[i].num << ""
<< stu[i].name << " "
<< stu[i].age << " "
<< stu[i].sex << " "
<< stu[i].score << endl;
}
return 0;
}
结构体调用自己
struct node
{
int a;
//struct node n;//无法调用因为还没定义结构体,还不知道结构体n的空间大小
struct node* n;//用指针指向一个地址,只需要知道存在就行
};