Qt 结构体赋值:使用指针操作 Student 结构体
要给结构体 struct *Student 赋值,可以通过以下步骤进行:
- 定义一个结构体
struct Student,包含需要的成员变量。比如:
struct Student {
int id;
std::string name;
int age;
};
- 创建一个结构体指针
struct *Student,并分配内存空间。比如:
struct Student *student = new struct Student;
- 使用指针访问成员变量,并给它们赋值。比如:
student->id = 1;
student->name = 'John';
student->age = 20;
- 最后,记得在使用完后释放内存空间。比如:
delete student;
原文地址: https://www.cveoy.top/t/topic/p4Mc 著作权归作者所有。请勿转载和采集!