remarknibor wrote:
> Rather than using threads, GUIs, etc., couldn't I just do the 
> following:
> 
>   time_t seconds1, seconds2;
>   char c;
>   string essay1;
> 
>   seconds1 = time (NULL);
>   do {
> 
>     if(kbhit()) {
>       c = getch();
>       essay1.append(1,c);
>       cout << c;
>     }
>     seconds2 = time (NULL);
> 
>   } while(seconds2 - seconds1 <= 600); // max time in seconds
> 
> I came up with it this morning and it seems to do the job. The 
> solution is to check the time after every key press.
> Any thoughts?
> 
> Robin.

While that might work for some cases, it won't handle the backspace key, 
delete key, arrow keys (not that getline would either), and won't ignore 
most other keys.

Since you say you are using Dev-C++, take a look at wxDev-C++ (Dev-C++ 
with wxWidgets).  Writing a GUI to do what you want is really 
straight-forward (and pretty much drag-n-drop).  You're fighting the 
natural evolution of your programming skills by trying to stick with 
something not up to the task of handling the task.  You're outgrowing 
the console and learning that the console is good for some things but 
not good for others.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to