//C++中结构体的不同之处 #include <iostream> #include <string> using namespace std; int main(void) { //自定义结构体类型 struct Student { string name;//姓名 int age;//年龄 void show(void) { cout << "我是" << name << ",今年" << age << "岁了" << endl; } }; }; cout << "姓名是:" << s.name << ",年龄是:" << s.age << endl; s.show(); cout << "------------------" << endl; Student* ps = &s; cout << "姓名是:" << ps->name << ",年龄是:" << ps->age << endl; ps->show();//(*ps).show(); cout << "----------------" << endl; Student s2 = {}; s2.show(); ; }