Exception Handling and Opening a File?

前端 未结 2 593
死守一世寂寞
死守一世寂寞 2020-12-29 01:41

Is it possible to use exceptions with file opening as an alternative to using .is_open()?

For example:

ifstream input;

try{
  input.ope         


        
2条回答
  •  -上瘾入骨i
    2020-12-29 02:10

    From the cppreference.com article on std::ios::exceptions

    On failure, the failbit flag is set (which can be checked with member fail), and depending on the value set with exceptions an exception may be thrown.

提交回复
热议问题