cant get ifstream to work in XCode

Posted by segfault on Stack Overflow See other posts from Stack Overflow or by segfault
Published on 2010-01-21T05:24:33Z Indexed on 2010/03/13 8:45 UTC
Read the original article Hit count: 313

Filed under:
|
|

No matter what I try, I cant get the following code to work correctly.

ifstream inFile;
inFile.open("sampleplanet");
cout << (inFile.good()); //prints a 1
int levelLW = 0;
int numLevels = 0;
inFile >> levelLW >> numLevels;
cout << (inFile.good()); //prints a 0

at the first cout << (inFile.good());, it prints a 1 and at the second a 0. Which tells me that the file is opening correctly, but inFile is failing as soon as read in from it. The file has more then enough lines/characters, so there is no way I have tried to read past the end of the file by that point.

File contents:

8
2
#level 2
XXXXXXXX
X......X
X..X..XX
X.X....X
X..XX..X
XXXX...X
X...T..X
XXX..XXX
#level 1
XXXXXXXX
X......X
X..X.XXX
X.X..X.X
X..XX..X
X......X
X^....SX
XXX.^XXX

© Stack Overflow or respective owner

Related posts about ifstream

Related posts about c++