Searching Files

Aug 16, 2012 at 6:33pm
So my question is this...if condition is met, it will exit the inner while and will re-execute the outer while (because the flag is still false...when it enters the inner while, will it start the file again?

If not how do I say start from the beginning of the file?

1
2
3
4
5
6
7
8
9
10
11
12
13
bool flag = false;

while(!flag) {
    ... some code ...

    while (!myfile.eof()) { 
        getline(myfile, inBuffer);

        ... compare some stuff ...
        ... if condition met -> flag = false & break
        ... if condition not met -> flag =  true and it will exit both loops when done reading the file
    }
}
Aug 16, 2012 at 7:50pm
from what i can understand, yes.
Aug 16, 2012 at 7:55pm
Don't check for eof
Aug 16, 2012 at 7:59pm
why should they not check eof?
Aug 16, 2012 at 10:10pm
It's inconsistent with its philosophy to treat an fstream as a file. It's a stream that's bound to a file.

http://www.cplusplus.com/forum/beginner/77102/#msg414551
Last edited on Aug 16, 2012 at 10:13pm
Topic archived. No new replies allowed.