/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fun.cpp
* 作 者:王飞
* 完成日期:2013 年1月 30日
* 版本号: v1.0
* 对任务及求解方法的描述部分:new和delete的应用
* 输入描述:略
* 问题描述:略
* 程序输出:如下
*/
#include <iostream>
#include <string>
using namespace std;
struct Student
{
int num;
string name;
char sex;
};
int main()
{
Student *stu; //定义结构体类型Student的数据指针变量stu
stu=new Student; //用new开辟一个存放Student的数据的指针变量stu
stu->name="li ming";
stu->num=1001;
stu->sex='M';
cout<<stu->name<<" "<<stu->num<<" "<<stu->sex<<endl;
delete stu; //撤销该空间
return 0;
}
截图:
心得体会:
在动态分布空间上为了解决内存空间的不足,将俩个一起用还是很有效果的