D
DiegoC
How can I know if any character has been typed without using the kbhit
of <conio.h>. The function should not block the program.
of <conio.h>. The function should not block the program.
How can I know if any character has been typed without using the kbhit
of <conio.h>. The function should not block the program.
Alf said:* DiegoC:
This is not covered by the standard language or library; use other
libraries (e.g. your operating system's API).
Well, there is std::cin.rdbuf()->in_avail() tocheck how many characters are
available for reading,
but it's not guaranteed to work correctly on all implementations.
Alf said:* Rolf Magnus:
AFAIK in_avail() is not required to check lower level buffers.
And when it does not, relying on it to check for interactive keypresses
may cause an infinite loop.
Or other bad things; I've not bothered to check out the finer details
of the modern iostreams since they're not usable for serious work (in
particular, reading anything but pure text has Undefined Behavior since
the conversion defers to sscanf which has UB for nonconforming input,
but to not scare newbies needlessly I don't usually mention that...).
Nothing is guaranteed to work correctly on all implementations, but
everything is guaranteed to work correctly on correct implementations.
Correct does not in this case, AFAICS, extend to provide the OP's
functionality.
Is there something I may have overlooked?
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.