#includeusing namespace std;
int add(int a,int b)
{
return a+b;
}
double add(double c,double d) //重载
{
return c+d;
}
char * add(char *e , char *f) //字符串连接使用strcat函数
{
strcat(e,f);
return e;
}
int main()
{
int a,b;
double c,d;
char e[100],f[100];
cin>>a>>b>>c>>d>>e>>f;
cout<<add(a,b)<<endl;
cout<<add(c,d)<<endl;
cout<<add(e,f)<<endl;
return 0;
}
错误是这样的:C:\Users\asus\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\CodeBlocks\211.c++.cpp||In function 'char* add(char*, char*)':|
C:\Users\asus\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\CodeBlocks\211.c++.cpp|16|error: 'strcat' was not declared in this scope|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
为什么这一段代码用codeblocks运行会有错误?
答案:1 悬赏:20
解决时间 2021-02-21 08:08
- 提问者网友:恋你成殇
- 2021-02-20 20:41
最佳答案
- 二级知识专家网友:星痕之殇
- 2021-02-20 21:38
仔细看你编译时候的错误:
error: 'strcat' was not declared in this scope
函数strcat需要 string.h 的头文件.
在你代码前面include:
#include <string.h>
error: 'strcat' was not declared in this scope
函数strcat需要 string.h 的头文件.
在你代码前面include:
#include <string.h>
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯