getch() in c++

Hi...
I want to get the input from the user, without making him to press 'ENTER' key. I could achieve this in c language, by using getch() function. But, this doesn't hold good for c++.
Please help me...
You need to use some third party library for this as pd|n curses
Notice that if you don't really need this is more a pain than useful
closed account (Lv0f92yv)
And this is because input is sent to the program (your program) from the operating system, which by default (linux/windows) is set to only forward said input on recieving the '\n' character at the shell/command line level.

Doing what you want to do is possible, but requires telling the OS to change its behavior a bit.
:o Thank you very much... Could you give me a small snippet with curses library.?
Last edited on
Here is a hello world example: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html

And here another example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <curses.h>

int main()
{
    initscr();
    char c;
    printw ( "enter any character besides 'q':\n" );
    do
    {
        c = getch();
        printw ( "\nYou entered %c \n", c );
        refresh();
    }
    while ( c != 'q' );

    endwin();
    return 0;
}
Topic archived. No new replies allowed.