我正在尝试使用fstream和异常,但始终使用崩溃崩溃的异常运行程序,编译器未报告错误。 我认为是MinGw编译器中的错误或与Windows系统的兼容性。
您能帮我解决我的问题吗?谢谢!
代码:::阻止17.12!修订版11256 Win32 / gcc版本3.4.5(mingw-vista special r3)/ Windows 7 ServicePack1
示例代码:
#include <iostream>
#include <fstream>
int main() {
int ivalue;
try {
std::ifstream in("in.txt");
in.exceptions(std::ifstream::failbit);
in >> ivalue;
} catch (std::ios_base::failure &fail) {
// handle exception here
}
}
```
Link:https://es.cppreference.com/w/cpp/io/basic_ios/exceptions
Compiller:
-------------- Build: Release in Exceptions (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -IC:\C++\TestExecLibs\Include -c C:\Programing\C&C++\Exceptions\main.cpp -o obj\Release\main.o
mingw32-g++.exe -o bin\Release\Exceptions.exe obj\Release\main.o -s "C:\Program Files\CodeBlocks\MinGW\lib\libcomctl32.a"
Output file is bin\Release\Exceptions.exe with size 784.50 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))-------------- Build: Release in Exceptions (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -IC:\C++\TestExecLibs\Include -c C:\Programing\C&C++\Exceptions\main.cpp -o obj\Release\main.o
mingw32-g++.exe -o bin\Release\Exceptions.exe obj\Release\main.o -s "C:\Program Files\CodeBlocks\MinGW\lib\libcomctl32.a"
Output file is bin\Release\Exceptions.exe with size 784.50 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))
After Run CMD:
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_ios::clear
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Process returned 3 (0x3) execution time : 2.948 s
Press any key to continue.
[CMD Window Result][1]
[1]: https://i.stack.imgur.com/vCudt.jpg