c++ - G++ Linux 终端中的 <curses.h>;<curse.h>;<conio.h> 问题

标签 c++ linux terminal g++

#include <iostream>
    using namespace std;
    #include <curses.h>  //#include <conio.h>
    int main()
    {
    initscr();
    char dir='a';
    int x=10,y=10;
    cout<<"Please press ENTER for EXIT...\n";
    while (dir != '\r')
    {
     cout<<"\n Your coordinates: " << x << ", " << y;
     cout<<"\n Select your destination: (N,S,E,W): ";
     dir = getch();
     if(dir =='n')
     y--;
      else if(dir=='s'))
     y++;
      else if(dir=='e'))
     x++;
      else if(dir=='w'))
     x--;
     }
    return 0;
    }

给出错误

msi@MSI-VR610:~/Desktop$ g++ adelseif.cpp -o adelseif
adelseif.cpp:5:42: fatal error: curses.h: No such file or directory
#include <curses.h>  //#include <conio.h>

所以我正在尝试使用替代目录 curse.h 和 ncurse.h 以及其他组合,但无论如何它都无法编译

最佳答案

您需要安装合适的包;对于 Ubuntu,这是 libncurses5-dev ;对于 Fedora,它似乎是 ncurses-devel .使用您的包管理器(apt-get、yum 等)安装它。

你也需要在库中链接;通过在编译命令中添加“-lcurses”或“-lncurses”来做到这一点(两者都适用于 Ubuntu;我不确定其他发行版)。

您的代码在“else if ...”行中有额外的右括号;当您使用可用的 curses.h 进行编译时,您将获得更多详细信息。

关于c++ - G++ Linux 终端中的 <curses.h>;<curse.h>;<conio.h> 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669052/

相关文章:

c++ - ISO C++ 禁止声明没有类型的 ‘transpose’ [-fpermissive]

linux - 挂载:未知文件系统类型 '0'

linux - 为什么 `stack --version` 显示的版本与安装的版本不同?

ios - 如何使用路径调用 cd 命令?

linux - Ubuntu:使用 curl 下载图像

c++ - 与 Lua 链接错误?

python - c++中的两个比较运算符,如python

linux - POSIX - 了解非阻塞发送实现

linux - 如何在不中断当前 session 的情况下启动程序?

C++ - 从缓冲区读取数据