使用new为结构分配内存而不是声明一个结构变量

时间:2023-01-08 20:39:24
// practice4-8.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
const int len = 70;
struct pizza 
{
	char brand[len];
	double diameter;
	double weight;
};

int _tmain(int argc, _TCHAR* argv[])
{
	using namespace std;
	pizza * ps = new pizza;
	cout<<"Enter pizza brand:";
	cin.getline(ps->brand,len);
	cout<<"Enter its diameter;";
	cin>>(*ps).diameter;
	cout<<"Enter its weight:";
	cin>>ps->weight;
	cout<<"****************************************"<<endl;
	cout<<ps->brand<<"\n"<<ps->diameter<<"\n"<<ps->weight<<endl;
	delete ps;
	system("pause");
	return 0;
}