non-delay mode read from cin

R

richard

I am trying to do non-delay mode read from cin, i.e.
char ch;
...
while( cin.getch(ch) )
{
...
}
I want getch to return whenever there is a char typed (not wait till
a newline is seen).

How do I do this? I am using linux if it matters.

thanks,

----RICH
 
J

John Harrison

richard said:
I am trying to do non-delay mode read from cin, i.e.
char ch;
...
while( cin.getch(ch) )
{
...
}
I want getch to return whenever there is a char typed (not wait till
a newline is seen).

How do I do this? I am using linux if it matters.

It's impossible in standard C or C++. The C FAQ is good on this topic, it
applies equally to C++.

http://www.eskimo.com/~scs/C-faq/q19.1.html

john
 
M

Mike Wahler

richard said:
I am trying to do non-delay mode read from cin, i.e.
char ch;
...
while( cin.getch(ch) )

'cin' does not have a member function 'getch()'.

It does have two members which extract a single character
(overloads of 'get()').

{
...
}
I want getch to return whenever there is a char typed (not wait till
a newline is seen).

Not possible with standard C++.
How do I do this? I am using linux if it matters.

Try looking at your implementation's documentation to see
if there's a platform-specific extension offered for this.

-Mike
 
A

Arijit

richard said:
I am trying to do non-delay mode read from cin, i.e.
char ch;
...
while( cin.getch(ch) )
{
...
}
I want getch to return whenever there is a char typed (not wait till
a newline is seen).

How do I do this? I am using linux if it matters.

thanks,

----RICH

Not possible in standard C++. Since you are using linux, check out the
GNU readline library.

-Arijit
 

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

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,518
Latest member
TobiasAxf

Latest Threads

Top