cpp使用new创建动态结构

#include<iostream>
using namespace std;

struct inflatable {
	char name[20];
	float volume;
	double price;
};
int main() {
	inflatable* ps = new inflatable;
	cout << "input name of inflatable item: ";
	cin.get(ps->name, 20);
	cout << "input volume in cubic feet: ";
	cin >> (*ps).volume;
	cout << "input price: $";
	cin >> ps->price;
	cout << "name: " << (*ps).name << endl;
	cout << "volume: " << ps->volume << endl;
	cout << "price: " << ps->price << endl;
	delete ps;
	return 0;
}

 


版权声明:本文为sdhdsf132452原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。