#include //结构体指针 //作用:通过指针访问结构体中的成员 //利用操作符 -> 可以通过结构体指针访问结构体属性 #if(0) struct Student { std::string name; //姓名 int age; //年龄 int score; //分数 }; int main() { //1、创建学生的结构体变量 struct Student s = { "张三" , 18 ,100 }; //2、通过指针指向结构体变量 struct Student* p = &s; //3、通过指针访问结构体变量中的数据 std::cout << "姓名:" << p->name << "年龄:" << p->age << "分数:" << p->score << std::endl; system("pause"); return 0; } //总结:想通过结构体的指针来访问结构体中的属性,需利用' -> ' #endif