Hi, I'm having trouble reading a file the way I want it to.
/*Textfile.txt*/
ROOM
Closet
Its too dark, you cant see anything.
EXIT
out Basement 1
ROOM
Basement
Its too dark, you need some sort of light to help you see.
EXIT
enter Closet 1
EXIT
up Dinning_Room 1
ROOM
Dinning_Room
It looks like no one is here. Everything looks old and dusty.
EXIT
down Basement 1
/*Function: Reads the file
*Parameter: string for file name, vector of Rooms
*Return: void
*/
void openFile(std::string fileName, std::vector<Room*> *room){
Room* _room;
std::string Name;
std::string Desc;
std::string Dir;
std::string check;
std::string check2;
bool exit;
std::ifstream file(fileName);
if (file.is_open())
{
while (file.good()){
std::getline(file, check);
if (check == "ROOM")
{
std::getline(file, Name);
std::getline(file, Desc);
_room = new Room(Desc, Name);
file >> check2;
if (check2 == "EXIT") {
file >> Dir >> Name >> exit;
_room->SetExit(Dir, Name, exit);
/*stores information from SetExit() in a room vector in Room Object, can have multiple "Exits"*/
std::cout << "Registered exits for " << _room->getName() << ": " << Name << std::endl;
std::getline(file, check2);
std::cout << check2;
}
room->push_back(_room);
}
}
file.close();
}
else
{
std::cout << "no file";
}
}
whats happening is that the Basement to Dining_Room is not registering.