双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

利用指针给一个字符串数组赋值,怎么做?

tomyail tomyail 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<iostream>
using namespace std;
struct CandyBar{
char name[20];
double weight;
int caloric;
};

CandyBar CandyFun(CandyBar &Candy,char *pName ="Millennium Munch",
double fWeight = 2.85,int fcaloric = 350);
int main(){
CandyBar myCandyBar;

cout <<"Enter the Candy's name:" ;
char pn[20];
cin.get(pn,20).get();
cout << "Enter the Candy's weight:";
double weight;
cin >> weight;
cout << "Enter the Candy's caloric:";
int caloric;
cin >> caloric;
CandyFun(myCandyBar,pn,weight,caloric);
}


CandyBar CandyFun(CandyBar &Candy,char* pName,double fWeight,int fcaloric){

Candy.name = *pName;
Candy.weight = fWeight;
Candy.caloric = fcaloric;
return Candy;
}

这是源代码,运行错误29 incompatible types in assignment of `char' to `char[20]' 位于 CandyFun函数的第一行?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
tomyail
C++ 语言 65,214 成员 250,514 内容