#include"iostream"
using namespace std;
struct box{
char maker[40];#include"iostream"
using namespace std;
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
}
void showstruct(struct box v);
int main()
{
struct box t1={ "hello123",
5,
4,
2,
40
};
showstruct(t1);
return 0;
}
void showstruct(struct box v)
{ using namespace std;
cout<<v.maker<<endl;
cout<<v.height<<endl;
cout<<v.width<<endl;
cout<<v.length<<endl;
cout<<v.volume<<endl;
}
float height;
float width;
float length;
float volume;
}
void showstruct(struct box v);
int main()
{
struct box t1={ "hello123",
5,
4,
2,
40
};
showstruct(t1);
return 0;
}
void showstruct(struct box v)
{ using namespace std;
cout<<v.maker<<endl;
cout<<v.height<<endl;
cout<<v.width<<endl;
cout<<v.length<<endl;
cout<<v.volume<<endl;
}
下面 是编译器编译的结果:
g++ 5.cpp
5.cpp:3:1: error: new types may not be defined in a return type
5.cpp:3:1: note: (perhaps a semicolon is missing after the definition of ‘box’)
5.cpp:10:29: error: two or more data types in declaration of ‘showstruct’
5.cpp: In function ‘int main()’:
5.cpp:21:14: error: ‘showstruct’ was not declared in this scope
#include"iostream"
using namespace std;
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
}
void showstruct(struct box v);
int main()
{
struct box t1={ "hello123",
5,
4,
2,
40
};
showstruct(t1);
return 0;
}
void showstruct(struct box v)
{ using namespace std;
cout<<v.maker<<endl;
cout<<v.height<<endl;
cout<<v.width<<endl;
cout<<v.length<<endl;
cout<<v.volume<<endl;
}
c++问题 到底是哪里出错了
答案:3 悬赏:40
解决时间 2021-01-30 10:59
- 提问者网友:风华是一指流沙
- 2021-01-30 02:24
最佳答案
- 二级知识专家网友:一只傻青衣
- 2021-01-30 03:01
你这段代码而言,具体的错误就是:
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
}
这个结构体定义后边漏掉了一个分号";"
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
}
这个结构体定义后边漏掉了一个分号";"
全部回答
- 1楼网友:强势废物
- 2021-01-30 05:01
#include"iostream"
using namespace std;
struct box{
char maker[40];
float height;
float width;
float length;
float volume;
};
void showstruct(struct box v);
int main()
{
struct box t1={ "hello123",
5,
4,
2,
40
};
showstruct(t1);
return 0;
}
void showstruct(struct box v)
{ using namespace std;
cout<<v.maker<<endl;
cout<<v.height<<endl;
cout<<v.width<<endl;
cout<<v.length<<endl;
cout<<v.volume<<endl;
}
定义结构体后加分号
- 2楼网友:一起来看看吧
- 2021-01-30 04:15
错在这句
sout<<item1+item2<<endl;
把 sout 改成 cout
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯