|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
struct Candybar
{
char name[30];
double weight;
int reliang;
};
void setcd(Candybar &a,char *d="Defu", const double b = 2.85 , const int c = 350);
int main()
{
Candybar g;
setcd(g);
std::cout << g.name;
return 0;
}
void stecd (Candybar &a ,char *d,const double b,const int c)
{
int e = 0;
while (d[e] != '\0')
{
a.name[e]= d[e];
e++;
}//对name赋值
a.weight = b;
a.reliang = c;
std::cout << a.name << std::endl;
std::cout << a.weight << std::endl;
std::cout << a.reliang << std::endl;
}
可以编译,运行错误
void setcd (Candybar &a ,char *d,const double b,const int c)
{
int e = 0;
while (d[e] != '\0')
{
a.name[e]= d[e];
e++;
}//对name赋值
a.weight = b;
a.reliang = c;
std::cout << a.name << std::endl;
std::cout << a.weight << std::endl;
std::cout << a.reliang << std::endl;
}
|
|