I need a crossplatform way of calling std::cin in non blocking way. I know it’s possible with threads, but maybe there is a better option? Threds seem to be overkill for this.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Standard C and C++ do not provide any means to do non blocking I/O. Typically, the C and C++ runtime environment does not see any input at all until the user has pressed the
<ENTER>key.So, the only options are really to use a separate thread to read the input, or to use platform-specific methods to do the non-blocking input (possibly wrapped so you can easily replace that part when porting to a different platform. Libraries like
ncursesprovide these input methods pre-wrapped for a number of platforms).