Help pls. how can I enter characters without enter ?

Jun 17, 2018 at 8:58pm
Help how to cin() && '\n' with std ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
   while( true )
   {
       if( cin.get() == 'w' )              //how to use without pressing enter?
       {
           cout<<"you have pressed w"<<endl;
       }
       else if( cin.get() == 's' )         //how to use without pressing enter?
       {
           cout<<"you have pressed s"<<endl;
       }
   }


  return 0;
}
Last edited on Jun 17, 2018 at 9:00pm
Jun 17, 2018 at 9:29pm
You probably need a function such as getch() from NCurses: https://www.gnu.org/software/ncurses/ (A library for doing terminal based interactions on POSIX systems). On Windows, you may be looking for PDCurses, which is basically the same thing ported to said platform (Google it up). Unfortunately, you can't really expect a cross-platform method for this. The other problem is this that you can't use cout and etc, only the NCurses functions e.g printw.
Topic archived. No new replies allowed.