#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 相当于python中的类
struct stu {
string name;
int age;
};
int main() {
// std::cout << "Hello, World!" << std::endl;
stu s; // 创建对象 在栈内存 有释放机制存在的不会太长久
s.name = "小米";
s.age = 19;
cout << s.name << endl;
cout<< s.age << endl;
// 创建对象 堆内存 无释放机制可以活的长久 且这个是对指针的解引用,得到的是一个对象
stu* s2 = new stu;
(*s2).name = "小花";
(*s2).age = 22;
cout << (*s2).name << (*s2).age << endl;
return 0;
}
C++中的结构体
最新推荐文章于 2024-08-25 11:55:57 发布