|
-
Nov 11th, 2001, 09:42 PM
#1
Thread Starter
Frenzied Member
Capture key press - console app
Is there a simple way of capturing a key press within a console app.
At the moment i'm doing this:
cout << "press any key to continue";
cin >> x;
but that looks messy as they first have to press a key, which is displayed after press any key to continue, and they then have to press enter/return aswell.
Cheers.
-
Nov 12th, 2001, 06:32 AM
#2
If you want the "Press any key to continue" kind of thing, where
the use just presses a key and the program goes on:
_getch()
Code:
#include <conio.h>
int ch;
ch = _getch();
-
Nov 12th, 2001, 09:57 AM
#3
#include <stdlib.h>
void main()
{
system("pause");
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 12th, 2001, 11:11 AM
#4
Thread Starter
Frenzied Member
Thanks you 2, I'm a bit disappointed i didn't think of the
system("pause") method myself though.
-
Nov 12th, 2001, 04:13 PM
#5
PowerPoster
On Visual C++, system("pause") does not work either.
-
Nov 13th, 2001, 09:47 AM
#6
Thread Starter
Frenzied Member
I'm using VC++ and it works fine in my console app. Although i've #include <cstdlib> instead of <stdlib.h> if that makes a difference.
-
Nov 13th, 2001, 09:56 AM
#7
PowerPoster
I never tried "cstdlib.h". I think it'll work for me.
-
Nov 13th, 2001, 12:28 PM
#8
Monday Morning Lunatic
C:
Code:
#include <stdlib.h>
int main(void) {
system("pause");
return 0;
}
C++
Code:
#include <cstdlib>
using namespace std;
int main() {
system("pause");
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|