6

I know that getch is not a standard C/C++ function but I tend to like it because it doesn't need you to press enter before returning. So I'd like to know if there is any equivalent in standard C++ that has the same effect (doesn't require you to press enter)?

I have read similar questions on this site but none of their answers say whether there is a standard and portable equivalent or not.

Mo Sanei
  • 445
  • 6
  • 22

2 Answers2

6

There is a portable-ish equivalent if you use one of the "curses" libraries, such as ncurses

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
0

Use ncurses. It's the best and simplest alternative out there.

Sample Code:

#include <ncurses.h>

 int main()
 {  
   initscr();                   /* Start curses mode          */
   printw("Hello World !!!");   /* Print Hello World          */
   refresh();                   /* Print it on to the real screen */
   getch();                     /* Wait for user input */
   endwin();                    /* End curses mode        */

   return 0;
 }
Acedev003
  • 51
  • 1
  • 7