Re: file reading problem
"Felix85" <a.pyro85@gmail.com> wrote in message
news:1146952143.449082.112240@i39g2000cwa.googlegroups.com...
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());
if ( ! infile.open() )
// Do something for error here.
// Display a message, return an r with rnum -1 or something
string roomNameIn, roomDescriptionIn;
int roomExitsIn[6];
infile >> rnum;
if ( ! infile >> rnum )
// Do something for error here.
// Display a message, return an r with rnum -1 or something
getline(infile, roomNameIn);
if ( ! getline( infile, roomNameIn ) )
// Do something for error here.
// Display a message, return an r with rnum -1 or something
getline(infile, roomDescriptionIn);
if ( ! getline(infile, roomDescriptionIn) )
// Do something for error here.
// Display a message, return an r with rnum -1 or something
infile >> roomExitsIn[0] >> roomExitsIn[1] >>
roomExitsIn[2] >> roomExitsIn[3] >> roomExitsIn[4] >> roomExitsIn[5];
if ( ! infile >> roomExitsIn[0] >> roomExitsIn[1] >>
roomExitsIn[2] >> roomExitsIn[3] >> roomExitsIn[4] >> roomExitsIn[5] )
// Do something for error here.
// Display a message, return an r with rnum -1 or something
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.
Put in the testing code and see if you get an error anywhere.
Otherwise, not enough information. Let us see how the class r is defined.
Let us see where you are trying to display the class r.