【问题标题】:Issue with <curses.h>;<curse.h>;<conio.h> in G++ Linux terminal<curses.h>;<curse.h>;<conio.h> 在 G++ Linux 终端中的问题
【发布时间】:2014-03-26 17:44:47
【问题描述】:
#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 以及其他组合,但它无论如何都无法编译

【问题讨论】:

标签: c++ linux terminal g++


【解决方案1】:

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

您也需要在库中链接;通过添加“-lcurses”或“-lncurses”来执行编译命令(两者都在 Ubuntu 上工作;我不确定其他发行版)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2021-01-11
    • 1970-01-01
    • 2019-12-05
    相关资源
    最近更新 更多