请教strcmp函数的用法!
时间:2011-12-18
来源:互联网
USACO上的题 c++ 提交上之后提示::
Compiling...
Compile error: your program did not compile correctly:
program.c: In function 'int main()':
program.c:29:26: error: 'strcmp' was not declared in this scope
--> 28: for(j=0;j<num;j++)
--> 29: if(0!=strcmp(a,name[j]))
program.c:39:25: error: 'strcmp' was not declared in this scope
--> 38: for(k=0;k<num;k++)
--> 39: if(!strcmp(a,name[j]))
Compile errors; end of this run.
下面d我的码:
/*
ID:qiushil3
PROG:gift1
LANG:C++
*/
#include<fstream>
#include<string>
using namespace std;
int main(void)
{
int num;
char a[20];
char name[20][20];
int money[20],mymoney[20];
int i,j,k,tt,mny,nn;
ofstream fout ("gift1.out");
ifstream fin ("gift1.in");
fin >> num;
for(i=0;i<num;i++)
{
fin >> name[i];
money[i]=0;
mymoney[i]=0;
}
for(i=0;i<num;i++)
{
fin >> a;
for(j=0;j<num;j++)
if(!strcmp(a,name[j]))
{
tt=j;//tt: number of the money's owner
break;
}
fin >> mny >> nn;
mny/=nn;
mymoney[tt]=mny*nn;
for(j=0;j<nn;j++)
for(k=0;k<num;k++)
if(!strcmp(a,name[j]))
money[j]+=mny;
}
//Output below this line
for(i=0;i<num;i++)
{
fout << name[i] << " ";
fout << money[i]-mymoney[i] << endl;
}
return 0;
}
作者: qiushile 发布时间: 2011-12-18
再加上这丫
作者: mingliang1212 发布时间: 2011-12-18
作者: timerfire 发布时间: 2011-12-18
#include <iostream>//最基本的一个啊
出来同样的错误提示啊。。。
作者: qiushile 发布时间: 2011-12-19
#include <string.h>
再加上这丫
加了啊
#include<string>
不一样???
作者: qiushile 发布时间: 2011-12-19
既然用了<iostream>
就要cin cout 啊!!
#include <string>是c++中才有的c没有
#include <string.h>是c的,c++只是兼容一下!也可以写成#include <cstring>
作者: timerfire 发布时间: 2011-12-19
作者: shenxinji 发布时间: 2011-12-19
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28