请教strcmp函数的用法!

爷们姓邱 2011-12-18 11:44:30
C++新手 望指教!
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;
}
...全文
468 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
爷们姓邱 2011-12-20
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 xphome 的回复:]

要不然每次读一行?getline(fin,XXX);
[/Quote]

fin不就是读一行的嘛?
黯然 2011-12-19
  • 打赏
  • 举报
回复
流的不懂...不过在我这可以运行,没输出就是了 //vc6.0
Karl_S 2011-12-19
  • 打赏
  • 举报
回复
不要用fin 和fout呢太非主流了吧!!
既然用了<iostream>
就要cin cout 啊!!
#include <string>是c++中才有的c没有
#include <string.h>是c的,c++只是兼容一下!也可以写成#include <cstring>


爷们姓邱 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mingliang1212 的回复:]

#include <string.h>

再加上这丫
[/Quote]
加了啊

#include<string>
不一样???
爷们姓邱 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 timerfire 的回复:]

#include <iostream>//最基本的一个啊
[/Quote]

出来同样的错误提示啊。。。
东风无眠 2011-12-19
  • 打赏
  • 举报
回复
编译是没有问题的呀

主要这个文件"gift1.in"里面要有内容啊
fin打开后,每次读取都是读取一行的内容
wfq0987 2011-12-19
  • 打赏
  • 举报
回复
编译没有问题的。
追求执着 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 luciferisnotsatan 的回复:]

引用 4 楼 qiushile 的回复:

引用 1 楼 mingliang1212 的回复:

#include <string.h>

再加上这丫

加了啊

#include<string>
不一样???

不一样
string.h是C库处理字符串的函数。如strcmp
string是C++的stl里的string
[/Quote]
++
luciferisnotsatan 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 qiushile 的回复:]

引用 1 楼 mingliang1212 的回复:

#include <string.h>

再加上这丫

加了啊

#include<string>
不一样???
[/Quote]
不一样
string.h是C库处理字符串的函数。如strcmp
string是C++的stl里的string
enic 2011-12-19
  • 打赏
  • 举报
回复
缺少头文件

hongwenjun 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 timerfire 的回复:]

不要用fin 和fout呢太非主流了吧!!
既然用了<iostream>
就要cin cout 啊!!
#include <string>是c++中才有的c没有
#include <string.h>是c的,c++只是兼容一下!也可以写成#include <cstring>
[/Quote]

fin 和 fout 只是自己定义 文件流对象
cin cout 是 C++ std namespces的 控制台 I/O 对象

fin 表示 输入的文件对象
fout 表示 输出的文件对象
steven30832 2011-12-19
  • 打赏
  • 举报
回复
#include <ctring>
xphome 2011-12-19
  • 打赏
  • 举报
回复
要不然每次读一行?getline(fin,XXX);
爷们姓邱 2011-12-19
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 lockedstar 的回复:]

编译是没有问题的呀

主要这个文件"gift1.in"里面要有内容啊
fin打开后,每次读取都是读取一行的内容
[/Quote]


gift1.in的内容:

5
dave
laura
owen
vick
amr
dave
200 3
laura
owen
vick
owen
500 1
dave
amr
150 2
vick
owen
laura
0 2
amr
vick
vick
0 0
Karl_S 2011-12-18
  • 打赏
  • 举报
回复
#include <iostream>//最基本的一个啊
iamnobody 2011-12-18
  • 打赏
  • 举报
回复
#include <string.h>

再加上这丫

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧