错误:楼层::楼层(常量字符串 &):无法打开文件

Error: Floor::Floor(const string &): cannot open file

本文关键字:楼层 文件 常量 字符串 错误      更新时间:2023-10-16

希望你做得很好。 我的代码有问题,当我尝试运行程序时,它会给我错误。 错误是:

错误:楼层

::楼层(常量字符串 &):无法打开文件

这是函数:

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,然后可以在文件名中断时打印出来,则可以看到程序尝试打开的文件名。作为第一步,请检查此文件是否存在,如果适用,请确保它未被任何其他程序打开(在某些环境中,一次只能打开一个进程的文件)。