C++ BuilderX为何无法对文件进行读取操作?这是Bug吗?
最近我碰到一个奇怪的问题:在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,并输出其中的内容。
请向这里有人碰到过类似的问题吗?你们是如何解决的?