C++读取TXT文件显示“open error”

#include
#include
using namespace std;
int main()
{
int a[10],i;
ifstream infile("f2.dat",ios::in);
if(! infile)
{
cout<<" open error "< exit(1);
}
for(i=0;i {infile>>a[i];
cout<<a[i];}
return 0;}
这段程序调试没有问题,但是会显示“open error”,如图所示

http://zhidao.baidu.com/link?url=LNGbSzxA_oF2Xvf_7k5EoRKO2F_4miKuUWjOOKqYbwYRJ5J-zceDKE3EP1W2MbkHr4DR6tUrsJWDjpL1ko0nmRxIXNbCPJf1XjMgp7-ZuJy

是不是f2.dat文件没在项目目录下?

试试能不能用ofstream打开,如果不存在会创建。然后用ifstream打开。。如果这种形式没错误,就是你文件没放了。如下:

    ofstream test("f2.dat");
    test.close();
    ifstream infile("f2.dat");

应该是文件路径不对造成的吧。。。。。。。。。。。