作用:通过指针访问结构体中的成员
- 利用操作符->可以通过结构体指针访问结构体属性
#include <iostream>
#include<cstring>
using namespace std;
//结构体指针
struct student
{
string name;
int age;
int score;
};
int main()
{
student s={"张三",18,100};
student *p=&s;//不能用int
cout<<"姓名"<<p->name<<endl;
cout<<"年龄"<<p->age<<endl;
cout<<"成绩"<<p->score<<endl;
return 0;
}