首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

编译不过解决方案

2012-03-21 
编译不过# includeiostream# includestringusing namespace stdstatic struct CandyBar{char name[20

编译不过
# include<iostream>
# include<string>
using namespace std;
static struct CandyBar
{
char name[20];
double weight;
double calorie;
}

int main()
{
CandyBar snack=
{
"Mocha Munch",
2.3,
350.0
};
cout<<snack.name<<"\n"<<snack.weight<<"\n"<<snack.calorie<<endl;
return 0;
}
D:\新建文件夹\45.cpp(12) : error C2628: 'CandyBar' followed by 'int' is illegal (did you forget a ';'?)
D:\新建文件夹\45.cpp(21) : error C2440: 'return' : cannot convert from 'const int' to 'struct CandyBar'


[解决办法]
static struct CandyBar
{
char name[20];
double weight;
double calorie;
}

后少了一个分号;

热点排行