I am trying to run this program in CodeBlocks using Ubuntu as operating system. The compiler is GNU GCC Compiler
#include <iostream>
#include <ncurses.h>
using namespace std;
int main()
{
cout << "ingrese letra" << endl;
char letra;
letra = getch();
cout << "Su letra fue: " << letra;
}
However, the code does not compile and gives me the following error:
reference to "stdscr" undefined
reference to "wgetch" undefined
I also tried to add "ncurses" to the compiler as I could read here but despite doing so I still cannot display the character on the screen (Although this time it compiles):
What other documentation could I read to see if I can compile projects that involve character manipulation?
I've read this article: "How to include or link ncurses/curses library in Codeblocks 13.12 in Ubuntu 16.04" but I can't find the boost directory (I don't copy the link because I don't have a reputation of more than 10)
You have successfully configured CodeBlocks by following the instructions in that article.
What happens is that ncurses needs an initialization before using its functions, and a final cleanup. Pre-initialization consists of calling initscr() , while before the end of the program it is necessary to call endwin() .
On the other hand, ncurses includes the concept of timeout , that is, doing something after a certain amount of time has passed without activity (for example, waiting for a key to be pressed), so it is necessary to disable it with timeout(-1) . With a negative parameter, the wait for the key is indefinite.
The complete code is as follows:
I hope it helps you.