C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-05-2009, 12:27 PM   #1
Registered User
 
Join Date: Oct 2006
Posts: 298
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.
Elkvis is offline   Reply With Quote
Old 02-05-2009, 01:07 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 7,252
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.
Daved is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
getch() equivalent in C++ hauzer C++ Programming 3 06-02-2009 05:54 PM
Another syntax error caldeira C Programming 31 09-05-2008 01:01 AM
kbhit() and getch() Equivalent.. ThLstN C Programming 1 03-11-2008 02:44 AM
Pls repair my basketball program death_messiah12 C++ Programming 10 12-11-2006 05:15 AM
FAQ: Is there a getch() (from conio) equivalent on Linux/UNIX? kermi3 FAQ Board 0 11-01-2002 11:56 AM


All times are GMT -6. The time now is 07:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22