tags:

views:

161

answers:

1

I was using the form used in one of the related questions. Only problem is that i keep getting right at the end of the file.

The file is an fstream and the str is a string.

Unhandled exception Microsoft C++ exception: std::ios_base::failure

while (getline(file, str)) 
{

}

if (cin.bad()) {
    // IO error
} else if (!cin.eof()) {
    // format error (not possible with getline but possible with operator>>)
} else {
    // format error (not possible with getline but possible with operator>>)
    // or end of file (can't make the difference)
}

+2  A: 

If you are getting std::ios_base::failure exceptions thrown it is most likely caused by you (or some code that you are using) turning them on for your file. They should be off by default. Just to test, you can try turning them off immediately before the while loop, but you probably need to investigate what is turning them on.

file.exceptions(std::ios_base::goodbit);
Charles Bailey
Thanks, didn't notice that some of the opening file exception example code had a, raw_data.exceptions ( ifstream::failbit | ifstream::badbit );
Roo