Xcode中的错误:线程1:EXC_BAD_ACCESS(代码= 1,地址= 0xe8)

时间:2018-11-24 02:05:21

标签: c++ xcode

这应该是一个c ++游戏,可以通过读取文件来工作。但是,我不太确定下面的代码有什么问题。当我输入文件名时,它给我这个错误(代码在下面,也显示有问题的行)。如果您无法修复它,您至少可以告诉我为什么这似乎在另一台计算机上可以正常工作,但是当我尝试在Xcode中进行编译时,它出了错吗?

#include "AdvRoom.h"



AdvRoom::AdvRoom()
{

}

bool AdvRoom::readRoom(ifstream &roomFile)
{
    bool success = true;
    char data[64];
    int pointer;

    while ((roomFile.get(data[0])) && data[0] == '\n') {}
    roomFile.unget();
    if (success && !roomFile.eof() && roomFile.good()) {
        roomFile.get(data, 64);
        this->number = atoi(data);
        roomFile.get(data[0]);
    }
    else success = false;

    if (success && !roomFile.eof() && roomFile.good()) {
        roomFile.get(data, 64);
        this->name = data;
        roomFile.get(data[0]);
    }
    else success = false;
    if (success && !roomFile.eof() && roomFile.good()) {
        roomFile.get(data, 64);
        while (data[0] != '-' && success) {
            this->description.push_back(data);
            if (success && !roomFile.eof() && roomFile.good()) {
                roomFile.get(data[0]);
                roomFile.get(data, 64);
            }
            else success = false;
        }
        roomFile.get(data[0]);
    }
    else success = false;

    if (success && !roomFile.eof() && roomFile.good()) {
        // Check for \n
        string direction;
        int destination = 0;
        string key;
        while (roomFile.peek() != '\n' && success) {
            if (success && !roomFile.eof() && roomFile.good()) {
                roomFile.get(data, 64, ' ');
                direction = data;
                while ((roomFile.get(data[0])) && data[0] == ' ') {}
                roomFile.unget();
                int i = 0;
                while ((roomFile.get(data[i])) && data[i] != '\n' && data[i] != ' ') {
                    ++i;
                }
                if (data[i] == ' ') {
                    data[i] = '\0';
                    destination = atoi(data);
                    roomFile.get(data, 64, '\n');
                    key = data;
                    roomFile.get(data[0]);
                }
                else if (data[i] == '\n') {
                    data[i] = '\0';
                    destination = atoi(data);
                    key = "";
                    //roomFile.get(data[0]);
                }
                AdvMotionTableEntry entry(direction, destination, key);
                this->motionTable.push_back(entry);
            }
            else success = false;
        }
    }
    else success = false;

    return success;
}

vector<string> AdvRoom::getDescription()
{
    vector<string> copyDesc = this->description;
    return copyDesc;
}

string AdvRoom::getName()
{
    string copyName = this->name;
    return copyName;
}

void AdvRoom::addObject(AdvObject obj)
{
    // This function should add the obj to the room.
    // It however, should not add the object to the room
    // if the room already contains the object.
    this->objects.push_back(obj);
}

AdvObject AdvRoom::removeObject(string objName)
{
    AdvObject deletedObj;
    // This function should remove the object with objName.
    for (int i = 0; i < this->objects.size(); ++i) {
        if (this->objects[i].getName() == objName) {
            deletedObj = this->objects[i];
            this->objects.erase(this->objects.begin() + i);
        }
    }

    return deletedObj;
}

bool AdvRoom::containsObject(string objName)
{
    // Returns true if object with objName is in the room.
    bool success = false;
    for (int i = 0; i < this->objects.size(); ++i) {
        if (this->objects[i].getName() == objName) {
            success = true;
        }
    }
    return success;
}

int AdvRoom::objectCount()
{
    return this->objects.size();
}

AdvObject AdvRoom::getObject(int index)
{
    return this->objects.at(index);
}

bool AdvRoom::hasBeenVisited()
{
    bool truth = this->isVisited;
    return truth;
}

void AdvRoom::setVisited(bool flag)
{
    this->isVisited = flag;
}

vector<AdvMotionTableEntry> AdvRoom::getMotionTable()
{
    vector<AdvMotionTableEntry> copyMotionTable = this->motionTable;
    return copyMotionTable;
}


int AdvRoom::getRoomNumber()
{
    int copyNumber = this->number;
    return copyNumber;
}

0 个答案:

没有答案