I am trying to improve my program by preventing a console from closing after my program is finished so that user can see that it is a console program and needs to be run from command prompt.
My method is to add cin.get() (or getchar()) before exit.
My problem is that when I test my program on Linux with wine, it messes up the terminal so that further user input is no longer visible. stty shows these extra options which where not present before:
Code: Select all
-brkint -icrnl
-icanon -iexten -echo
If I don't do cin.get(), then everything is fine.
Here is my minimal example enter.cpp:
Code: Select all
#include <iostream>
int main(int argc, char* args[]) {
std::cout << "Press ENTER" << std::endl;
std::cin.get();
std::cout << std::endl;
return 0;
}
i686-w64-mingw32-g++ -m32 -mconsole -static enter.cpp -o enter.exe
Then run it like this:
wine ./enter.exe
afterwards the terminal is unusable as the user input is not visible.
thus I need to reset my terminal with reset command.
So my questions are:
1) why cin.get() and getchar() in wine modify stty?
2) is there a better way of stopping console from closing?
For now I made a bash script wrapper around wine to restore stty, but this is not acceptable.