Well, I am writing a program that conducts a rather difficult analysis, and I would like to quickly stop it.
I added signal(SIGINT, terminate);at the beginning of the main and specific end, for example:
void terminate(int param){
cout << endl << endl << "Exit [N]ow, or [A]fter this url?" << endl;
std::string answer;
cin >> answer;
if(answer[0] == 'n' || answer[0] == 'N'){
terminateParser();
exit(1);
}else if(answer[0] == 'a' || answer[0] == 'A'){
quitAfterUrl = true;
}
}
On linux, this worked the way I expected it to wait for user input. But when I try to do the same in windows, it still shows the message and exits.
Is there any way to stop SIGINT immediately after closing the program?
Update:
when i tried
BOOL WINAPI handler(DWORD dwCtrlType)
{
if (CTRL_C_EVENT == dwCtrlType)
{
}
return FALSE;
}
as suggested by Gregory, the program was still unceremoniously exiting without stopping user input.
Update 2: I'm not quite sure I did this, but now the code works. Thank you all for your help.