Using another header for conio.h

Hello,

I would like to write a C++ programme on Ubuntu,
which reacts immediately to the input without pressing enter.
(-> I cannot use the header #include <conio.h> due to the reason that I am working on an UNIX system)

For instance:
I press on my keyboard the key "a", but instead of showing "a" in the terminal,
the programme should show "p".

For the last two days, I tried to do this with the header #include <ncurses.h>.
Unfortunately, it doesn't work.

Therefore, I would like to ask for your request.


With conio.h it would be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream> 
#include <conio.h> 
#include <string> 
using namespace std;

int main(void) 
{
	char c;
	c = getch();
	
	while(true)
	{
	
		if(c=='a')
		{
		putch('p');
		}
	
		else
		{
		putch(c);
		}
		
	c = getch();
		
	}
	
  cin.sync();              
  cin.get(); 
}


How can I realise the programme without using #include <conio.h>?


With best regards
quark42
You could create your own version of conio library if you so desire. There are several examples of getch() alternatives available on the net if you search "linux getch()". And remember this function is available in the curses library as well.
Hi jlb,

thank you for your answer.

I do not know what I should use instead of getch() and putch().
All my research on the net hadn't worked out.

Can you please post the source code with #include <ncurses.h>?
I do not know what I should use instead of getch() and putch().
All my research on the net hadn't worked out.

Where have you been looking? Googling "ncurses" yields close to 500,000 different links and within the first page there are several links for the actual documentation of this library. Several of the other links have pages and pages of sample code.

If you're just interested in getch() then a simple Goolge of "linux getch" yields about 132,000 different links many showing exactly how to implement this function to work in Linux.

So it looks to me that either you need to hone your search skills or that you want someone to give you a complete working solution for your particular problem. If you can't find, read, and understand documentation for the features you want to read then I suggest you stick with standard C++ functions instead.
Topic archived. No new replies allowed.