#include <iostream>
using namespace std;
struct Student //结构体的定义
{
//成员属性
string name; //姓名
int age; //年龄
double score;//分数
};
int main()
{
//结构体变量创建的方法一:
struct Student s1;
s1.name = "张三";
s1.age = 18;
s1.score = 99;
cout << "姓名:" << s1.name << " 年龄:" << s1.age << " 分数:" << s1.score << endl;
//结构体变量创建的方法二:
struct Student s2 = { "李四",19,88 };
cout << "姓名:" << s2.name << " 年龄:" << s2.age << " 分数:" << s2.score << endl;
}
C++结构体的定义和使用
最新推荐文章于 2024-08-25 23:11:21 发布