帮我看看这段代码。谢谢

wiw 2002-12-26 06:12:55
//---------------------------------------------------------------------------
#include <fstream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
char buff[80];
ifstream infile("c:\\sa.txt");
if(!infile)
{cout<<"打开文件失败";
return 0;
}
while(!infile.eof())
{
infile.getline(buff,sizeof(buff));
cout<<buff<<endl;
}
infile.close();
cout<<endl<<"press any key to continue...";
getch();
return 0;
}
//---------------------------------------------------------------------------
这代码有什么错?
...全文
19 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxy007 2002-12-26
  • 打赏
  • 举报
回复
喂,你是在bcb的哪里写这些代码啊?控制台吗?
你这程序要在控制台程序里面写的,正如wjh1014说的,要
Console Application
在vc里面也要这个。
GaoLun 2002-12-26
  • 打赏
  • 举报
回复
好了 我这里也要加 #include <iostream.h>

现在我加了 #include <iostream.h> 可以 通过
cxy007 2002-12-26
  • 打赏
  • 举报
回复
当然不用include <iostream.h>,因为fstream.h包括了iostream.h了。
错误代码说什么?
wjh1014 2002-12-26
  • 打赏
  • 举报
回复
不用加#include <iostream.h>。
我编译了没有问题。
File->New->Console Wizard

Source Type: C++
右边Console Application.
wjh1014 2002-12-26
  • 打赏
  • 举报
回复
char buff[80];
定义空间太小,如果一行的长度大于80的话,getline会一直读这一行。造成程序死循环。
GaoLun 2002-12-26
  • 打赏
  • 举报
回复
不加的话 只有一个错误
加了之后就成

[Linker Error] Unresolved external '__InitVCL' referenced from E:\CBUILDER6\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '__ExitVCL' referenced from E:\CBUILDER6\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl


为什么??
kingfish 2002-12-26
  • 打赏
  • 举报
回复
没问题啊
codecb 2002-12-26
  • 打赏
  • 举报
回复
是少了
#include <iostream.h>

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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