Page 1 of 1

[solved] GNU compiler and conio.h

Posted: Mon Feb 11, 2013 6:21 pm
by KeesA
Hallo,
Now I want to run a program which I wrote in C++ for Windows on Linux Mint.
Unfortunally, one of the headerfiles (conio.h) is not supported by GNU :shock:
I tried to use wxWidget in Wine but met some problems.
Now I use Code::Blocks which uses GNU compiler.
The function which I like to keep is getch() or _getch().
The reason is that the user of my program can press any key to continue without pressing <enter> afterwards when I use getch().
Does anybody know how a good alternative?
tnx a lot.

Re: GNU compiler and conio.h

Posted: Mon Feb 11, 2013 7:01 pm
by xenopeek
ncurses.h has a getch fuction, the file is in /usr/include/ncurses.h. You need to install ncurses-dev package to get it.

Re: GNU compiler and conio.h

Posted: Mon Feb 11, 2013 7:31 pm
by KeesA
I did already and found out that getch() has to be repleaced by getch.
But when assigning to a char variable, I get an error.

error: invalid conversion from ‘int (*)()’ to ‘char’ [-fpermissive]|

Is this about a function object or function pointer?
Or, I hope, someting less complicated and easy to solve?

Re: GNU compiler and conio.h

Posted: Mon Feb 11, 2013 9:26 pm
by KeesA
Now I know the interpretation of this fault message.
It says that you can't assign a refference to a function to a char.
But when I put () afer getch, I get:

Telebase 3.1 .cpp|| undefined reference to `stdscr'|

What does this mean?
Any thoughts?

Re: GNU compiler and conio.h

Posted: Tue Feb 12, 2013 3:20 am
by xenopeek
Don't know about that, but here is the bit about keyboard handling in the ncurses programming howto, might help: http://www.tldp.org/HOWTO/NCURSES-Progr ... /keys.html

Re: GNU compiler and conio.h

Posted: Tue Feb 12, 2013 6:30 pm
by KeesA
Thank you for the link.
I found out already, that one thing is importent to use curses or ncurses and that is to link it with your program.
Code::Blocks -> project -> Build options -> Linker settings -> Add
Here I typed: curses and ncurses.
Now I can write: char bar = getch(); without any problems. :D
Unfortunally the program "falls through" the getch statement. :oops:
Maybe someone knows how this can happen (it always worked fine in the Windows Dos box).
At the moment I am searching for the most simple solution to run my program like I did in Windows.

Re: GNU compiler and conio.h

Posted: Wed Feb 13, 2013 11:28 pm
by KeesA
Problem is solved.
I found this:

http://stackoverflow.com/questions/7469 ... e-in-linux

and it works!

Only, in addition to that, I had to write cin.ignore(); before the getch(); statements.
When getch(); is in a loop or recursive function, cin.ignore(); has to be put above that and not in the looping.