How watch for and extract single char from cin?

D

Dick Bridges

I guess I'm more of a newbie than I'd thought. I simply want to wait for at
least one byte (character?) to appear and then cin.get() or cin.read() that
character - without waiting for some delimiter to appear. I would have
thought this would be a common pattern for event-driven keystroke processing
but I can't find any examples of how it would be done using c++ iostreams.

Can someone point me toward a book, article, or example?

TIA
 
J

Jack Klein

I guess I'm more of a newbie than I'd thought. I simply want to wait for at
least one byte (character?) to appear and then cin.get() or cin.read() that
character - without waiting for some delimiter to appear. I would have
thought this would be a common pattern for event-driven keystroke processing
but I can't find any examples of how it would be done using c++ iostreams.

Can someone point me toward a book, article, or example?

TIA

There is absolutely no standard, portable way of doing this. C++ does
not provide or support keystrokes, all I/O is abstracted into
iostreams or FILE * streams. And in almost every operating system
today, you can start your program from a shell and make sure that its
standard input stream comes from a file or another device and has no
connection at all to a keyboard, assuming the system has one.

You need to ask in a group that specifically supports your compiler/OS
combination to see what sort of platform-specific non-standard
extensions it provides to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top