F
Felix85
here is my method for reading in a file:
static room room::file2Room(int rnum){
ostringstream filename;
filename << "../gamefiles/rooms/" << rnum <<
".room";
ifstream infile(filename.str().c_str());
string roomNameIn, roomDescriptionIn;
int roomExitsIn[6];
infile >> rnum;
getline(infile, roomNameIn);
getline(infile, roomDescriptionIn);
infile >> roomExitsIn[0] >> roomExitsIn[1] >>
roomExitsIn[2] >> roomExitsIn[3] >> roomExitsIn[4] >> roomExitsIn[5];
room r;
r.setRoomNumber(rnum);
r.setRoomName(roomNameIn);
r.setRoomDescription(roomDescriptionIn);
r.setRoomExits(roomExitsIn[0], roomExitsIn[1],
roomExitsIn[2], roomExitsIn[3], roomExitsIn[4], roomExitsIn[5]);
return r;
}
there are no compile errors but it reads in the file incorrectly.
here is the file it reads from:
0
Test Room
You are standing in a test room
1 2 -1 4 5 6
when i output the result to the screen it comes up:
Test Room
[ ]
instead of:
Test Room
You are standing in a test room
[ n s w u d ]
ive been trying to fix this for about 6hrs and still cant find the
problem.
any help will be appreciated.
static room room::file2Room(int rnum){
ostringstream filename;
filename << "../gamefiles/rooms/" << rnum <<
".room";
ifstream infile(filename.str().c_str());
string roomNameIn, roomDescriptionIn;
int roomExitsIn[6];
infile >> rnum;
getline(infile, roomNameIn);
getline(infile, roomDescriptionIn);
infile >> roomExitsIn[0] >> roomExitsIn[1] >>
roomExitsIn[2] >> roomExitsIn[3] >> roomExitsIn[4] >> roomExitsIn[5];
room r;
r.setRoomNumber(rnum);
r.setRoomName(roomNameIn);
r.setRoomDescription(roomDescriptionIn);
r.setRoomExits(roomExitsIn[0], roomExitsIn[1],
roomExitsIn[2], roomExitsIn[3], roomExitsIn[4], roomExitsIn[5]);
return r;
}
there are no compile errors but it reads in the file incorrectly.
here is the file it reads from:
0
Test Room
You are standing in a test room
1 2 -1 4 5 6
when i output the result to the screen it comes up:
Test Room
[ ]
instead of:
Test Room
You are standing in a test room
[ n s w u d ]
ive been trying to fix this for about 6hrs and still cant find the
problem.
any help will be appreciated.