这段程序基本正确,但是我的VS2013已知不能运行strcpy,所以没有出现结果,但是问题不大
#include<iostream>
#include<string>using namespace std;
struct CandyBar
{
char *name;
double weight;
int energy;
};
void set(CandyBar &Bar,string n = "Millennium Munch", double w=2.85, int e=350);
void Show(CandyBar &Bar);
int mian()
{
CandyBar initial = { "Millennium Munch", 2.85, 350 };
CandyBar &first = initial;
Show(first);
cout << "The follow information entered :" << endl;
char *m; double w; int e;
m="Bar name :";
w=0.54;
e=1230;
set(first, m, w, e);
Show(first);
return 0;
}
void set(CandyBar &Bar, char *a, double w, int e)
{
Bar.name =a;
Bar.weight = w;
Bar.energy = e;
}
void Show(CandyBar &Bar)
{
cout << "CandyBar name :" << Bar.name << endl;
cout << "CandyBar weight :" << Bar.weight << endl;
cout << "CandyBar energy :" << Bar.energy << endl;
}