Difference between casting ifstream to bool and using ifstream::is_open()

徘徊边缘 提交于 2019-12-04 07:30:29

No. is_open checks only whether there is an associated file, while a cast to bool also checks whether the file is ready for I/O operations (e.g. the stream is in a good state) (since C++11).

is_open

Checks if the file stream has an associated file.

std::basic_ios::operator bool

Returns true if the stream has no errors occurred and is ready of I/O operations. Specifically, returns !fail().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!