Среда выполнения cra sh с использованием исключений fstream в c ++ - PullRequest
1 голос
/ 17 апреля 2020

Я пытаюсь использовать fstream и исключения, но всегда запускаю программу, использующую исключение, которое вызывает sh, об ошибках не сообщалось от компилятора. Я думаю, это ошибка компилятора MinGw или несовместимость с моей windows системой.

Не могли бы вы помочь мне решить мою проблему. Спасибо!

Код :: Блоки 17.12! rev 11256 Win32 / g cc версия 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
...