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

// practice4-8.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
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<<"****************************************"<brand<<"\n"<diameter<<"\n"<weight<

你可能感兴趣的:(c++学习历程)