Search code examples
c++consoleiononblocking

Non-blocking console input C++


I'm looking for a (multiplatform) way to do non-blocking console input for my C++ program, so I can handle user commands while the program continually runs. The program will also be outputting information at the same time.

What's the best/easiest way to do this? I have no problem using external libraries like boost, as long as they use a permissive license.


Solution

  • I would do this by creating separate a thread which calls normal blocking IO functions and pass it a callback function which it would call when it got input. Are you sure you need to do what you said you want to do?

    As for outputting information at the same time, what would happen if the user was in the middle of typing some input and you printed something?