奇怪的fstream问题

时间:2015-07-13 15:17:01

标签: c++ fstream ifstream

我所写的所有程序都出现了一个奇怪的错误,即使它们位于同一目录中,我也不再阅读它们被引用的文件。我尝试过我编写和测试的旧程序,并且几个月没有触及,但现在它们返回了我的错误消息。我甚至写了一个简单的程序来测试它:

#include <iostream>
#include <fstream>

using namespace std;

int main() {
    fstream openFile;
    int num, cnt=0;

    openFile.open("data.dat");

    if (!openFile) {
        cout << "ERROR opening file" << endl;
    } else {
       cout << "I'm open!" << endl;
       while(openFile >> num)
        cout << num << endl;
        cnt++;
    }

    cout << cnt << endl;

    system("PAUSE");
    return(0);
}

档案信息:

1
2
5
66
9
4
2

这将返回ERROR消息,并将cnt返回0.该文件与可执行文件位于完全相同的目录中。 究竟是什么导致了这个?我的程序有问题吗?

0 个答案:

没有答案
相关问题