c++文本文件不工作了
C++ Textfiles Not Working Now?
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()
来确定导致错误的原因,见这里
相关文章:
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- 我的文件无法正常工作,无法从C++文件中读取上下文
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 有没有办法关闭文件? fclose 不能很好地工作
- G++ 在生成文件中使用时停止工作
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
- 使用.cpp文件让 RcppArmadillo 在 Rstudio 中工作
- 读取二进制文件大小的短自上周以来停止工作
- 我的 PowerShell 脚本无法按预期工作(用于编译C++文件)
- 不同文件的类,如何使其工作?
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- C Visual Studio代码不使用工作区中的单个文件夹编译
- 在循环工作时,首先将两个文件读为向量,但仅次于迭代一次
- 在Qt中使用工作线程将数据写入文件的正确方法是什么?
- OpenCV:文件存储操作员">>"在一个项目中工作,但不在另一个项目中工作(在同一类上)
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 程序在我的C++工作区中找不到头文件
- 从工作目录 QtWebEngine 读取文件
- 不完整的参数错误,包括其他.cpp文件中的postgres.cpp工作文件