[solved] GNU compiler and conio.h

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
KeesA

[solved] GNU compiler and conio.h

Post 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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: GNU compiler and conio.h

Post 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.
Image
KeesA

Re: GNU compiler and conio.h

Post 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?
KeesA

Re: GNU compiler and conio.h

Post 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?
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: GNU compiler and conio.h

Post 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
Image
KeesA

Re: GNU compiler and conio.h

Post 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.
KeesA

Re: GNU compiler and conio.h

Post 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.
Locked

Return to “Other topics”