结构体CandyBar,往第一个成员里赋值程序报错,显示表达式必须是可更改的左值,求指教。
#include <iostream>
#include <cstring>
using namespace std;
const int SLEN=30;
struct CandyBar{
char Name[SLEN];
double weight;
int heat;
};
void setinfo(CandyBar c, string nam, double w)
{
c.Name= nam;//报错
c.weight = w;
c.heat = 350;
}
void display(CandyBar cc)
{
cout << "The name is" << cc.Name << endl;
cout << "The weight is" << cc.weight << endl;
cout << "The heat is" << cc.heat << endl;
}
int main()
{
CandyBar cc;
//用后面的三个参数值,完成对第一个参数变量cc 的初始化)
setinfo(cc,"WW",3.35);
//显示参数cc的具体信息,显示格式如下:
//The name is WW
//The weight 3.35
//The heat is 350
display(cc);
}