使用new创建动态结构
2017-03-25 10:11
796 查看
#include <iostream> struct inflatable //struck defination { char name[20]; float volume; double price; }; int main() { using namespace std; inflatable* ps= new inflatable;//为结构体分配内存空间 cout<<"Enter name of inflatable item: "; cin.get(ps->name,20);//method 1 for member access cout<<"Enter volume in cubic feet: "; cin>>(*ps).volume;//method 2 for member acess cout<<"Enter price: $"; cin>>ps->price; cout<<"Name: "<<(*ps).name<<endl;//method 2 cout<<"Volume: "<<ps->volume<<" cubic feet\n";//method 1 cout<<"Price: $"<<ps->price<<endl;//method 2 //如果结构标识符是结构名,则使用句点运算符;如果标识符是指向结构的指针,则使用箭头运算符 delete ps; return 0; }
相关文章推荐
- 使用new创建动态结构和自动, 静态, 动态三种存储方式
- c++ primer plus 习题5.7(使用new为结构创建动态数组)
- 1.5 使用new创建动态结构和自动, 静态, 动态三种存储方式
- 【C++学习笔记】使用new创建动态结构
- C++使用new创建动态结构
- 创建结构candybar,要求用new来动态分配结构数组
- 使用new创建动态数组
- new 创建动态结构小例子
- 使用new来为动态分配结构数组并赋值
- PowerShell小技巧之使用New-Module命令动态创建对象
- c++ 使用new动态的创建指定大小的二维数组
- 【动态代理】使用构造方法创建代理类、使用 newProxyInstance.newProxyInstance()创建代理类
- C++学习笔记四之使用new来创建动态数组
- 使用new创建动态数组
- flash embed fonts–动态创建文本时嵌入字体_解决_rotation和_alpha不能使用的问题
- 使用FastReport 3.0及以上版本创建动态报表的几个技巧
- ABAP--如何创建动态结构的报表
- ABAP--如何创建动态结构的报表
- [自我总结]如何使用VS2005中的OLEDB的JET SQL驱动来动态创建数据表!
- (转)使用JavaScript和DOM动态创建表格