1

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.

user1873947
  • 1,781
  • 3
  • 27
  • 47

1 Answers1

2

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 ncurses provide these input methods pre-wrapped for a number of platforms).

Bart van Ingen Schenau
  • 15,488
  • 4
  • 32
  • 41
  • There are "ncurses" and similar libraries available for several different platforms, which contains code to deal with "get key without blocking" and other similar things. – Mats Petersson Jan 14 '13 at 19:20