How would one listen for keyboard input, without causing the program to pause waiting for the input? For instance say you have something like
float num = 0;
bool runloop = true;
for(int i=0; i<1000000 && runloop; i++{
n += some_time_consuming_transformation(i);
// How to listen for input at this point? e.g. waitforoptionalinput() function
}
printf("n is %d\n", n);
And you want it to run indefinitely unless the user enters some key, say "q". And if the user enters "q" it would call some other function, similar to
function verify(){
printf("Are you sure you want to stop here? (y/n)\n");
char y_or_n[1];
cin >> y_or_n;
if(strcmp("y",y_or_n)==0 || strcmp("Y",y_or_n)==0) runloop = false;
}
Also, would there perhaps be a way to in advance tell the program to listen for keyboard input at any point - without explicitly calling a waitforoptionalinput() at a certain point in the program.