Thread: getting input from buffer

  1. #1
    Autobots Transform! Dunners's Avatar
    Join Date
    Feb 2005
    Posts
    23

    getting input from buffer

    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

  2. #2

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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

  4. #4
    Autobots Transform! Dunners's Avatar
    Join Date
    Feb 2005
    Posts
    23
    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

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    No it doesn't, I just tried it.
    Try this code
    Code:
    #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;
    }
    EDIT
    strike all the above, I was using cin.get(). I'm getting tired now all this coding is doing me no good.
    Oh, then nvr mind
    Last edited by MadCow257; 02-21-2005 at 09:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Can't seem to come to conclusion : cin.ignore()
    By SkyHi in forum C++ Programming
    Replies: 8
    Last Post: 05-13-2005, 08:57 PM
  3. How can you tell if the input buffer is empty?
    By Punkture in forum C Programming
    Replies: 1
    Last Post: 06-04-2003, 05:10 PM
  4. text input buffer clearing
    By red_Marvin in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2003, 03:17 PM
  5. Flushing the input buffer.
    By civix in forum C++ Programming
    Replies: 6
    Last Post: 08-19-2002, 06:41 PM