cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
exiting a loop by pressing a key
exiting a loop by pressing a key
Apr 3, 2008 at 12:08pm UTC
Kvakac
(12)
Hello
I have a do-while loop that compares some variables stored in a file with new data captured from a device. What I want to do, is when a certain (or any, it doesn't really matter) key is pressed, the loop ends.
Thanks in advance.
Apr 3, 2008 at 12:18pm UTC
psault
(133)
What compiler are you using? I know if you use Borland, their <conio.h> file has a function called kbhit(); You can say, in your loop:
1
2
3
4
if
(kbhit()) {
char
c=getch();
break
; }
Apr 3, 2008 at 12:33pm UTC
Kvakac
(12)
Thanks a lot, that is exactly what I needed!
I'm using MSVC++ by the way, so it works there too.
Last edited on
Apr 3, 2008 at 12:41pm UTC
Topic archived. No new replies allowed.