The Library effectively calls rdbuf()->close(). This function is called by the destructor of basic_fstream when the stream object goes out of scope and is not usually invoked directly.
If an error occurs during operation, setstate(failbit) is called.
fstrm.close(); //called by the destructor of object of basic_fstream
cout << fstrm.is_open()<<endl;
}
return 0;
}
OUTPUT:
Explanation:
After writing into the file, it has been checked whether file is open or not. Since close() was not called, it was open. But after close() was called, file had been disconnected from the fstream object. Therefore, we get output to be boolean '1' for true as file had been open and boolean '0' for false as file had been closed.
Comments