为什么我不能使用 conio.h 或 ncurses.h?

amo*_*mol 6 programming compiling c ncurses

我是 Ubuntu 的新用户。我用 C 写了一个简单的程序。当我尝试编译它以使用 时conio.h,编译器给了我致命的错误。所以我尝试了 ncurses.h,但我仍然遇到同样的错误。

Eli*_*gan 5

为什么conio.h不可用

g_p主要在评论中回答了这个问题

conio.h在 Linux 中不存在。您需要使用cursesncurses。但是,如果您收到类似 的错误fatal error: curses.h: No such file or directory',则表示未安装此库。

有关 conio.h(以及它如何特定于 DOS/Windows)的更多信息,请参阅有关它的 Wikipedia 文章

为什么ncurses.h不可用,以及如何修复它

至于ncurses,需要安装libncurses5-dev安装 libncurses5-dev(或libncursesw5-dev安装 libncursesw5-dev) 包,然后在编译时将-lncurses参数传递给gcc,例如:

gcc -Wall -g -o hello hello.c -lncurses
Run Code Online (Sandbox Code Playgroud)

请参阅如何在命令行程序中创建简单的类似窗口的元素?及其来源)以获取更多信息。