错误:楼层::楼层(常量字符串 &):无法打开文件
Error: Floor::Floor(const string &): cannot open file
希望你做得很好。 我的代码有问题,当我尝试运行程序时,它会给我错误。 错误是:
错误:楼层::楼层(常量字符串 &):无法打开文件
这是函数:
Floor::Floor(const string &f_name) {
ifstream tmp(f_name.c_str());
tmp.ignore(100,'n');
int c;
while(!tmp.eof()) {
c = tmp.get();
if (c != ' ' && c != '#' &&
c != 'L' && c != 'D' &&
c != 'K' && c != 'X' &&
c != 'E' && c != 'S' &&
c != 'A' && c != 'n' &&
c != EOF) {
cout << "Bad input file" << endl;
exit(EXIT_FAILURE);
}
}
fill_floor(f_name);
}
这是我的主要:
#include <iostream>
#include <cstdlib>
#include <ctime> // only for seed random generator
#include "game.h"
using namespace std;
int main(int argc, char **argv) {
srand(time(0));
// init game
Game game(2);
// let's play ;)
do {
game.print_floor();
} while(game.make_turn());
if (game.stuck()) cout << "No posible moves. You lose =(" << endl;
else if (game.won()) cout << "Congratulation!" << endl;
else cout << "Bye!" << endl;
return 0;
}
我正在使用MakeFile来编译文件。
您需要发布更多代码才能获得很多帮助,但我可以提供一些常规调试技巧。使用所有警告启用和调试信息编译代码(即将CFLAGS=-g -Wall
放入makefile中),然后使用gdb /path/to/binary
调试代码。如果使用命令 break FLOOR::FLOOR
,后跟 run
,然后可以在文件名中断时打印出来,则可以看到程序尝试打开的文件名。作为第一步,请检查此文件是否存在,如果适用,请确保它未被任何其他程序打开(在某些环境中,一次只能打开一个进程的文件)。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 如何将内容数组写入文本文件?
- 错误:楼层::楼层(常量字符串 &):无法打开文件