c++文本文件不工作了

C++ Textfiles Not Working Now?

本文关键字:工作 文件 文本 c++      更新时间:2023-10-16

Edit: solved…对多个文件使用相同的ifstream显然不是一个好主意。

我刚买了一台新的笔记本电脑,并将我的c++项目转移到新电脑上,我突然在阅读Code::Blocks的文本文件时遇到了问题…我不知道为什么。

旧的笔记本电脑运行32位的操作系统,而新的是64位的。我不知道那会不会有什么影响。

下面是不再工作的那部分代码:

ifstream myfile;
//edit: a different file is read here, in exactly the same manner as below
//when I comment it out, the following section works as it's meant to...
//what am I doing wrong that they won't work successively
myfile.open("version.txt");
if (myfile.is_open()) {
    out("This message displays...");
    //OK so apparently 'eofbit' is thrown here...but the file has content in it?
    while (myfile.good()) {
        out("This message doesn't, when it should...");
        getline(myfile,version_info);
    }
    myfile.close();
}

edit: 'out'只是一个显示消息的自定义脚本,顺便说一下

尝试使用myFile.rdstate()来确定导致错误的原因,见这里