|
|
|
|
![]() ![]() |
Apr 19 2005, 07:13 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
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: CODE cout << "Enter barcode:\r\n"; cin.get(ch); while (int(ch) != 13) { cout << ch; cin.get(ch); line = line+ch; } myFunction( line ); This post has been edited by serverph: Apr 19 2005, 07:35 PM |
|
|
|
Apr 20 2005, 08:36 AM
Post
#2
|
|
|
Legend Killer ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 678 Joined: 15-April 05 From: Singapore Member No.: 5,697 |
How does it work?
|
|
|
|
Apr 23 2005, 02:55 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
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. 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; } |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 01:14 AM |