ctrl-z is the end of file marker for terminal input
ctrl-c is the interrupt signal, which kills your program unless you handle or ignore it
Code:
#include <iostream>
#include <string>
#include <signal.h>
using namespace std;
volatile bool sigCaught = false;
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_CRT_signal.asp
void catcher ( int signal ) {
sigCaught = true;
}
int main ( ) {
bool done = false;
/* catch ctrl-C, test sigCaught below if you want to know about it */
// signal ( SIGINT, catcher );
/* ignore ctrl-C */
signal ( SIGINT, SIG_IGN );
while ( !done ) {
char input[100];
while ( !done &&
cin.getline(input,sizeof input) ) {
string sInput = input;
cout << sInput << endl;
if ( sInput == "exit" ) {
done = true;
}
}
if ( cin.eof() ) {
cin.clear();
cout << "EOF detected, ignored" << endl;
}
}
return 0;
}