Searching Files

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
    }
}
from what i can understand, yes.
Don't check for eof
why should they not check eof?
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
Topic archived. No new replies allowed.