Question

is there any way to check if there is something in cin? I tryied peek() but if there isn't anything peek() waits for input and that isn't what I want. Thank you

Was it helpful?

Solution

You cannot use cin to read keystrokes, and then go on to do something else if there is nothing available, which I think is what you may want. cin is a buffered stream and simply does not work in that way. In fact, there is no way of doing this using Standard C++ - you will have to use OS specific features.

OTHER TIPS

C++ streams and streambufs are synchronous, that is they block until there is enough input to read. There is no portable way to check a stream asynchronously. Consider calling peek() from a separate thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top