Thread: equivalent to getch in c++

  1. #1
    Registered User
    Join Date
    Oct 2006

    equivalent to getch in c++

    now, I know what you're thinking... "this is going to be another one of those 'how can I get the functionality of system("pause") without calling system()?' threads....

    well, you're almost right.

    Am I the only one who thinks it is a pretty big oversight not to have the ability to read a single character from an std::istream, without waiting for a delimiter? seriously, how hard would it be to add a function which, when called, it would sit and wait until there was at least one character available in the input buffer and then it would remove that character from the buffer and immediately return its value, regardless of whether a delimiter was encountered. I really don't understand why it is not a part of the standard library. it would be such a useful function to have, and would certainly see more use than many other features of the c++ standard library.

    just looking for thoughts/opinions on this.

  2. #2
    Registered User
    Join Date
    Jan 2005
    The problem is that standard C++ knows nothing of the "console" it is reading from. Not all consoles will be able to send characters immediately.

    And note that it isn't waiting for the delimiter. The console you use provides the data for the application after <enter> is pressed, regardless of what delimiter you specify. That's just how your console works.

    The solution is to have a non-standard method that does exactly what you ask and works on the consoles that allow for it. That is what getch() is, and that is why there is no new solution.

    The only thing the standard could do is add an interface that could be implemented with getch() on platforms that support that type of behavior, but I'm not sure that's really necessary when getch() will suffice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getch() equivalent in C++
    By hauzer in forum C++ Programming
    Replies: 3
    Last Post: 06-02-2009, 05:54 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. kbhit() and getch() Equivalent..
    By ThLstN in forum C Programming
    Replies: 1
    Last Post: 03-11-2008, 02:44 AM
  4. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  5. Replies: 0
    Last Post: 11-01-2002, 11:56 AM