Set ctrl/c handler

Hi,
I want implement this.
What i do?
1
2
3
while( !flagStop ) { ... }

Set this flag in your ctrl/c handler.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <csignal>

static volatile std::sig_atomic_t flagStop = 0 ;

extern "C" void ctrl_c_handler(int) { flagStop = 1 ; }

int main()
{
    // http://en.cppreference.com/w/cpp/utility/program/signal
    std::signal( SIGINT, ctrl_c_handler ) ;

    std::cout << "Ctrl-C to quit" << std::flush ;
    while( !flagStop ) { /* ... */ }
}
Hi,
I when Press "Ctrl+C" show the below exception.
http://upload7.ir/imgs/2014-05/56828962479881871382.jpg
It is just a first chance exception.
(The program is being run under an attached debugger, and the debugger is given the first chance).

Uncheck "break when this exception type is thrown" and click on "Continue".

Or, run the program without attaching the debugger CTRL+F5 (IIRC).
Topic archived. No new replies allowed.