#include<iostream>
#include<string>
using namespace std;
struct person {
string name;
int age;
char M;
double weight; //默认公有成员
};
int main(){
person stu = { "本人",16,'f',58.25 };
cout << stu.name << endl;
cout << stu.age << endl;
cout << stu.M << endl;
cout << stu.weight << endl; //对象名.成员名访问结构体中的变量
return 0;
}
c++中,结构体是类的一种特殊形式,关键字——“struct”。