Hey all,
is it possible to use cin to grab a character from the buffer without the user having to press enter, etc? i.e. as soon as the key is pressed the character goes into the variable used with the cin?
Cheers
Hey all,
is it possible to use cin to grab a character from the buffer without the user having to press enter, etc? i.e. as soon as the key is pressed the character goes into the variable used with the cin?
Cheers
"Yes, I rather like this God fellow. He's very theatrical, you know, a pestilence here, a plague there. Omnipotence. Gotta get me some of that."
- Stewie Griffin
I'm fairly certain there isn't a standard C/C++ function to do this, however you may find some alternatives under the FAQ entry for how to stop your program from ending immediately after starting it. A common sultion is getch() in conio.h, but remember that that isn't standard.
edit: Yes, THAT faq entry, and I see it uses conio.h
I've tried using getch() but the problem I have is that it requires enter to be pressed, I want to grab a character and move on as soon as the user presses that character key, no hanging round if you get what I mean.
-----------------------------------------------------
strike all the above, I was using cin.get(). I'm getting tired now all this coding is doing me no good.
Cheers for the help guys
"Yes, I rather like this God fellow. He's very theatrical, you know, a pestilence here, a plague there. Omnipotence. Gotta get me some of that."
- Stewie Griffin
No it doesn't, I just tried it.
Try this code
EDITCode:#include <iostream> #include <conio.h> using namespace std; int main() { char character; cout << "Please Enter A Key\n"; character = getch(); cout << character; cout << "\n"; return 0; }
Oh, then nvr mindstrike all the above, I was using cin.get(). I'm getting tired now all this coding is doing me no good.
Last edited by MadCow257; 02-21-2005 at 09:00 PM.