C++ BuilderX为何无法对文件进行读取操作?这是Bug吗?

Botton2008 2004-07-14 01:00:28
最近我碰到一个奇怪的问题:在C++ BuilderX中调试C++程序时,只要是涉及到打开文件的操作,总是提示无法打开文件!

我的源代码如下:

#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
cout << "* * This programme tests the file output operation * *\n\n";

string filename;

cout << "Please input the file name: ";
cin >> filename;
ifstream infile(filename.c_str());

if (!infile) {
cerr << "oops! cannot open \"" << filename << "\"!!"
<< endl;
exit(1);
}

string outstream;
while (infile >> outstream)
cout << outstream << "\n";

cout << "\nPress any key to exit..." << endl;
getch();

return 0;
}

编译环境:C++ BuilderX Enterprise V1.0.1.103
系统环境:Windows XP Professional SP1

无论我指定哪类文件,out、dat或txt,CBX均提示无法打开文件。我确定已经将文件Test.txt放在源程序所在的目录下,并预先指定了文件的内容。

奇怪的是,该程序在C++ Builder 6.0和Dev-C++ V4.9.8.0中调试一切正常,可以打开Test.txt,并输出其中的内容。

请向这里有人碰到过类似的问题吗?你们是如何解决的?
...全文
234 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Botton2008 2004-08-31
  • 打赏
  • 举报
回复
本问题已经找到解决方法:
即给文件添加完整的路径 Drive Letter:/path1[/path2...]/filename。
befree 2004-07-21
  • 打赏
  • 举报
回复
"oops!"?
kerbcurb 2004-07-17
  • 打赏
  • 举报
回复
必须给出路径,至于对路径有无中文以及中文路径会不会产生问题,不太清楚
Botton2008 2004-07-16
  • 打赏
  • 举报
回复
To befree:

就是提示文件无法打开,
oops! cannot open "text.txt"!
Botton2008 2004-07-15
  • 打赏
  • 举报
回复
是不是我的CBX设置有问题?
zmy9709 2004-07-15
  • 打赏
  • 举报
回复
还是中意标准c
befree 2004-07-15
  • 打赏
  • 举报
回复
你的具体出错信息是什么?
Botton2008 2004-07-14
  • 打赏
  • 举报
回复
songhtao: 我在CBX下也尝试过用其它的编译器,但除了Borland的编译器可以正常工作外,其余的编辑器均提示因缺少某些文件而无法编译,我估计是设置方面的问题,希望能有高手指点一下!
Botton2008 2004-07-14
  • 打赏
  • 举报
回复
Befree: 可我的就是不行啊!?
befree 2004-07-14
  • 打赏
  • 举报
回复
试过了,可以出来,没有问题
befree 2004-07-14
  • 打赏
  • 举报
回复
是不是一定要给出路径
我不懂电脑 2004-07-14
  • 打赏
  • 举报
回复
BCBX不会有这样的bug的

不过你用BCBX想向你请教一下:
BCBX号称跨平台,可是我在windows下用的个人版编好程序后,在平台选择中选择linx可是不能编译是怎么回事?难道要到linx下才能编译吗?可是这样的话,linx下和windows下连头文件都不同,跨平台特性就大打折扣了。
kerbcurb 2004-07-14
  • 打赏
  • 举报
回复
win2k,BCBX个人版,可以打开文件,你给出路径了吗?

13,870

社区成员

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

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