kvarnerexpress 0 Report post Posted April 19, 2005 (edited) Is there an easy way to make my 9 lines of code timeout in 5 minutes(that is no barcode has been entered for 5 mins) and if it timesout have it kill my program? Code: cout << "Enter barcode:\r\n";cin.get(ch);while (int(ch) != 13){ cout << ch; cin.get(ch); line = line+ch;}myFunction( line ); Notice from serverph: Code enclosed in proper tags. Edited April 19, 2005 by serverph (see edit history) Share this post Link to post Share on other sites
hype 0 Report post Posted April 20, 2005 How does it work? Share this post Link to post Share on other sites
osknockout 0 Report post Posted April 23, 2005 Technically, no since std::cin halts the program until some key response occurs.You'd have to test for keystrokes using your own code, which can take some time.But anyway, here's you five minute time out code. #include <iostream>#include <ctime.h>int main(){ clock_t x; x = clock () + 300 * CLK_TCK; //300 seconds = 5 minutes while (x > clock()) //basically test for 5 minutes in clock ticks { //place keytest code here... }return 0;} Share this post Link to post Share on other sites