A
Alex Buell
I have a small text file which consist of the following data:
[[[
-1 -1 -1 1
You are in a small square room.
0 -1 -1 -1
You are in a big round room.
]]]
And the code I've written is as follows:
[[[
Rooms getRoomDataRecords(string roomDataFile)
{
Rooms rooms;
ifstream ifs(roomDataFile.c_str());
if (!ifs.is_open())
{
cout << "Eh? Could not open " << roomDataFile << " for
reading." << endl;
return rooms;
}
while (!ifs.eof())
{
int n, w, e, s;
string line;
ifs >> n >> w >> e >> s;
cout << "1: " << n << " " << w << " " << e << " " <<
s<< endl;
getline(ifs, line);
cout << "2: " << line << endl;
rooms.push_back(Room(n, w, e, s, line));
}
ifs.close();
return rooms;
}
]]]
The trouble is, I can't work out why it goes into an infinite loop
reading the information from the text file!
Can anyone enlighten me as to what I am doing wrong?
[[[
-1 -1 -1 1
You are in a small square room.
0 -1 -1 -1
You are in a big round room.
]]]
And the code I've written is as follows:
[[[
Rooms getRoomDataRecords(string roomDataFile)
{
Rooms rooms;
ifstream ifs(roomDataFile.c_str());
if (!ifs.is_open())
{
cout << "Eh? Could not open " << roomDataFile << " for
reading." << endl;
return rooms;
}
while (!ifs.eof())
{
int n, w, e, s;
string line;
ifs >> n >> w >> e >> s;
cout << "1: " << n << " " << w << " " << e << " " <<
s<< endl;
getline(ifs, line);
cout << "2: " << line << endl;
rooms.push_back(Room(n, w, e, s, line));
}
ifs.close();
return rooms;
}
]]]
The trouble is, I can't work out why it goes into an infinite loop
reading the information from the text file!
Can anyone enlighten me as to what I am doing wrong?