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

Botton2008 Botton2008 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近我碰到一个奇怪的问题:在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,并输出其中的内容。

请向这里有人碰到过类似的问题吗?你们是如何解决的?
...全文
评论 13
收藏 已收藏
分享
返回顶部
Botton2008
C++ Builder 13,871 成员 102,696 内容