Configure ncurses in Codeblocks using Ubuntu

1

I am trying to run this program in CodeBlocks with Ubuntu 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 throws me as an error:

  

reference to "stdscr" without defining

     

reference to "wgetch" undefined

I also tried to add to the compiler "ncurses" how I could read here but despite doing so I still do not can display the character on the screen (Although this time compiles):

What other documentation could I read to see if I can compile projects that involve character manipulation?

I have read this article: "How to include or link ncurses / curses library in Codeblocks 13.12 in Ubuntu 16.04" but I can not find the boost directory (I do not copy the link because I do not have a reputation of more than 10)

    
asked by jqc 04.07.2017 в 05:44
source

1 answer

0

You have configured CodeBlocks correctly by following the instructions in that article.

What happens is that ncurses needs initialization before using its functions, and a final cleanup. The initialization is to call 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 when a certain time has passed without activity (for example, waiting for press a key), so it is necessary to deactivate it with timeout (-1) . With a negative parameter, the wait for the key is undefined.

The complete code is as follows:

#include <iostream>
#include <ncurses.h>

using namespace std;

int main()
{
    char letra;

    initscr();
    timeout( -1 );

    cout << "ingrese letra" << endl;
    letra = getch();

    cout << "Su letra fue: " << letra;

    endwin();
    return 0;
}

I hope it helps you.

    
answered by 04.07.2017 / 12:56
source