fstream::open sets the fail flag up.How to find the cause?

this is the line with fstream::open



1
2
3
4
std::fstream file;    
       
file.open("flights",std::ios::binary | std::ios::in );

What confuses me is that there is another function in the same file that opens the file successfully every time but this one fails. Bad flag is not set. Only fail flag is.

Can i somehow find out what is causing the problem?
Last edited on
Does the other function open the files as binary too?
Make sure the file isn't open somewhere else for writing.

By the way, don't use .open() and .close() - instead, let RAII handle opening and closing the file for you. Explicitly calling those member functions is only useful in special circumstances - doing it in other cases leaves extra room for human error.
Topic archived. No new replies allowed.