Closing a file stream does not reset error flags. Opening new file resets them in C++11, but not in earlier versions, so if at any time error happened, fin.fail() will return true even after opening new file. Call .clear() manually after closing file. Additionally it is better to use is_open() member funtion to chec if file was open.