here code.
#include<iostream> int main() { std::string str; while(true) { std::cout<<"enter string \n"; alarm(3); getline(std::cin,str); // calling function in other class, , return here (if not entered string in 3 sec) } return 0; }
after 2 sec exiting program. but, want continue calling function , return same getline(). possible?? thanks
if read reference page of alarm
see that:
the
alarm()
function shall cause system generatesigalrm
signal process after number of realtime seconds specified seconds have elapsed.
you need catch sigalrm
signal, example using sigaction
system call.
Comments
Post a Comment