#include <iostream>
#include "string"
#include "bubbleSort.h"
using namespace std;
//创建学生的数据类型
struct Student {
//成员列表
string name; //姓名
int age; //年龄
};
int main() {
//创建方式一:先创建,再赋值
struct Student student1;
student1.name = "张三";
student1.age = 10;
cout << "姓名:" << student1.name << "\t年龄:" << student1.age << endl;
//创建方式二:直接赋值
struct Student student2 = {"李四", 18};
cout << "姓名:" << student2.name << "\t年龄:" << student2.age << endl;
//创建方式三,声明时赋值
struct Person {
string name;
int age;
} person;
person.name = "王五";
person.age = 20;
cout << "姓名:" << person.name << "\t年龄:" << person.age << endl;
}
创建结构体变量的三种方法
最新推荐文章于 2024-08-25 11:21:51 发布