While loop with EOF()

Hi Everyone,

I have done a search though here and found similar problems but in my situation I need to have a while loop or some kind of loop.

Anyways so like the others my code is also picking up an extra character at the end of the file. in command prompt when I used cout to troubleshoot it shows up with a blank character, a screendump of the output is below.

I guess my question is what other alternative do I have or is there a way around this? Thanks

char i;
ifstream fileIn(file);
while (!fileIn.eof()){
i = fileIn.get();
if (isValid(i)){
myList.push_back(maze(i));
}
else {
cout << "\n" << "!! Maze file contains invalid characters !!" << "\n";
myList.clear();
//break;
}
}
fileIn.close();

command prompt output:
#
true
#
true
#
true
#
true
#
true
s
true
 
false

!! Maze file contains invalid characters !!
never mind i figured it out lol

had to i = fileIn.get(); out of the loop but also have it after the loop.
Don't loop on EOF.
1
2
3
4
char c;
while (fileIn.get( c )) {
  ...
}

Hope this helps.
Topic archived. No new replies allowed.