- スレを勃てるまでもないC/C++の質問はここで 24 [転載禁止]©2ch.net
48 :デフォルトの名無しさん[sage]:2015/12/08(火) 21:33:55.11 ID:y1mdlUK+ - 以下のコードについて、Win+Mingw 上での結果と Ubuntu 上での結果が異なります
#include <iostream> #include <fstream> #include <system_error> int main () { using namespace std; ifstream is; is.exceptions(ifstream::failbit | ifstream::badbit); try { is.open("xxx"); /* 存在しないファイル */ } catch (ifstream::failure e) { cerr << "ifstream::failure" << endl; } catch (system_error e) { cerr << "system_error" << endl; } catch (exception e) { cerr << "exception" << endl; } catch (...) { cerr << "other_error" << endl; } return 0; } Win+Mingw $ g++ --version g++.exe (tdm64-1) 5.1.0 $ g++ -std=c++14 a.cc && ./a exception Ubuntu $ g++ --version g++ (Ubuntu 4.9.2-10ubuntu13) 4.9.2 $ g++ -std=c++14 a.cc && ./a.out ifstream::failure Windows 側で ifstream::failure や system_error を捕捉できていないのはなぜでしょうか?
|