0

I have this much cleaner variant to system("Pause") that waits for the user to press enter:

#include <iostream>
void pause()
{
    std::cin.get();
    std::cin.ignore();
}

However, I couldn't find a clean variant to system("CLS") (or system("clear")), so I switched the whole application to ncurses. After some reading I found out that ncurses has its own set of I/O functions and that std::cout and std::cin got replaced with echo() and getch().

That function pause() also has to be converted to ncurses, but my problem is that I don't know the correct equivalent to std::cin.ignore.

  • Off topic: You may find `void pause() { std::cin.ignore(std::numeric_limits::max(), '\n'); }` a wee bit more reliable if you only want to exit on enter. Your version may leave crap in the stream to be picked up by subsequent stream reads. – user4581301 Jun 26 '17 at 05:57
  • Can you not use `getch()` itself to achieve the effect of `pause()`? You'd want to call `noecho()` before `getch()` to hide the input character. – Azeem Jun 26 '17 at 06:34

1 Answers1

0

You can discard input in curses using these functions (not just ncurses):

  • flushinp

    The flushinp routine throws away any typeahead that has been typed by the user and has not yet been read by the program.

  • intrflush

    If the intrflush option is enabled (bf is TRUE), and an interrupt key is pressed on the keyboard (interrupt, break, quit), all output in the tty driver queue will be flushed, giving the effect of faster response to the interrupt, but causing curses to have the wrong idea of what is on the screen. Disabling the option (bf is FALSE) prevents the flush. The default for the option is inherited from the tty driver settings. The window argument is ignored.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105