newを使用して構造配列を動的に割り当て、値を割り当てる

604 ワード

// practice4-9.cpp :              。
//

#include "stdafx.h"
#include 
#include 
#include 
using namespace std;
struct CandyBar 
{
	string brand;
	double weight;
	int calorie;
};
int _tmain(int argc, _TCHAR* argv[])
{
	int i;
	CandyBar * ps =new CandyBar[3];
	//         
	ps[0].brand="pizza hut";
	ps[1].brand="pizza down";
	cout<>ps[2].weight;
	cout<>ps[2].calorie;
	for (i=0;i<3;++i)
	{
		cout<
newに作成された動的構造配列の値付け方法には問題があります.もっと简単なはず