#include <iostream>
#include <string.h>
using namespace std;
struct Student
{
string name;
int num;
char sex;
};
int main()
{
Student *p;
p = new Student; //用new运算符开辟一个存放Student类型的数据指针变量p
p -> name = "Wang Ming";
p -> num = 21431;
p -> sex = 'm';
cout << p -> name << endl << p -> num << endl << p -> sex << endl;
delete p;
cout << "Hello world!" << endl;
return 0;
}
Code::Blocks运行,内容参考谭浩强C++程序设计第2版。
new和delete的使用以及struct结构体是使用
最新推荐文章于 2023-01-01 21:47:42 发布