How to clear exception mask in ifstream?

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

I set the exception mask failbit of an ifstream by doing:

#include <iostream> #include <fstream>  int main()  {     try {         std::ifstream in("in.txt");         in.exceptions(std::ifstream::failbit);     } catch (std::ios_base::failure &fail) {         // handle exception here     } } 

Is there any way I can clear or restore the exception mask?

回答1:

Found the solution:

std::ifstream::iostate old_state = in.exceptions (); 

will save the old exception mask.



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