-
June 25th, 2009, 02:46 PM
#1
modifying a loop with input
hey guys, so i am doing a project in which i need to be able to get input to alter the processes of a loop while it is running, but without disrupting the loop- so, if the user enters a character and hits enter, for instance, the value of some variable in the loop would be changed, but otherwise the loop continues on unstopped. is there a way to do this? thanks!
-
June 25th, 2009, 03:10 PM
#2
Re: modifying a loop with input
You will need to perform the loop in a worker thread and regularly (e.g. each iteration) check some shared resource, such as a bool variable.
In your main thread you then set the bool variable when you want the for-loop to stop.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
June 26th, 2009, 03:21 AM
#3
Re: modifying a loop with input
Originally Posted by iochinome
hey guys, so i am doing a project in which i need to be able to get input to alter the processes of a loop while it is running, but without disrupting the loop- so, if the user enters a character and hits enter, for instance, the value of some variable in the loop would be changed, but otherwise the loop continues on unstopped. is there a way to do this? thanks!
Try kbhit if you are using windows platform. Unfortunately C++ istream classes do not support asynchronous input. So, there is no standard way of doing it.
-
June 26th, 2009, 12:00 PM
#4
Re: modifying a loop with input
Originally Posted by rohshall
Try kbhit if you are using windows platform. Unfortunately C++ istream classes do not support asynchronous input. So, there is no standard way of doing it.
Actually, you could use a second thread. Do all your work (the loop) in the thread, and have your main thread waiting on input.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|