something like kbhit

D

DevarajA

How can i know if there are characters in the standard input using only
standard c++? I want to stop a loop when any key is pressed.
 
A

Artie Gold

DevarajA said:
How can i know if there are characters in the standard input using only
standard c++? I want to stop a loop when any key is pressed.

You cannot.

HTH,
--ag
 
D

DevarajA

rossum ha scritto:
As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.

rossum



The ultimate truth is that there is no ultimate truth

The faq talks about a keyboard.. and I know that c++ doesnt require a
keyboard, but somewhere there must be an input stream, so I just want to
know if there is even one character on it without stopping the program
(the function looks at the stream, if it's empty returns 0, otherwise it
returns 1). I think this could be possible.
 
L

Lionel B

DevarajA said:
rossum ha scritto:

The faq talks about a keyboard.. and I know that c++ doesnt require a
keyboard, but somewhere there must be an input stream, so I just want
to know if there is even one character on it without stopping the
program (the function looks at the stream, if it's empty returns 0,
otherwise it returns 1). I think this could be possible.

No, it really, really, really isn't. There are frequently OS-specific libraries that will do what you want, though. Have
you actually looked at the FAQ 15.17?
 
D

DevarajA

Lionel B ha scritto:
No, it really, really, really isn't. There are frequently OS-specific libraries that will do what you want, though. Have
you actually looked at the FAQ 15.17?

Yes but i can't get it working. Anyway i'm already using a non-standard
function that works perfectly, I just wanted to make it standard to
avoid problems when porting.
 
L

Lionel B

DevarajA said:
Lionel B ha scritto:

Yes but i can't get it working.

What's the problem (I'm assuming you're on a Posix system)? If it's C++ related, why not post it here? Else in a Unix
programmers ng, maybe?
Anyway i'm already using a
non-standard function that works perfectly, I just wanted to make it
standard to avoid problems when porting.

Right... well as I guess you've gathered by now, you're out of luck there. If you can get the Posix solution working
that will at least increase your portability to a lot of systems (and you've already got kbhit and all the conio.h stuff
on Win32... don't know about Mac).

Cheers,
 
D

DevarajA

Lionel B ha scritto:
What's the problem (I'm assuming you're on a Posix system)? If it's C++ related, why not post it here? Else in a Unix
programmers ng, maybe?

the faq tells me to "poll", but i don't know how to poll
 
A

Alan Johnson

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
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top