Linux 上的 <conio.h> 头文件在哪里?为什么我找不到 <conio.h>?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8792317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the <conio.h> header file on Linux? Why can't I find <conio.h>?
提问by janniks
Possible Duplicate:
How to implement getch() function of C in Linux?
What is the equivalent Linux
version of the conio.h
header file from MS-DOS?
MS-DOS 头文件的等效Linux
版本是conio.h
什么?
Is there a way to replace its functionality? e.g. getch()
有没有办法替换它的功能?例如getch()
I'm using
gcc
and the text editorGeany
to compileC
code.
我正在使用
gcc
和文本编辑器Geany
来编译C
代码。
采纳答案by Sangeeth Saravanaraj
conio.h
is a C
header file used in old MS-DOS compilers to create text user interfaces. Compilers that targeted non-DOS operating systems, such as Linux, Win32 and OS/2, provided different implementations of these functions.
conio.h
是C
旧 MS-DOS 编译器中用于创建文本用户界面的头文件。针对非 DOS 操作系统(如 Linux、Win32 和 OS/2)的编译器提供了这些函数的不同实现。
The #include <curses.h>
will give you almost all the functionalities that was provided in conio.h
该#include <curses.h>
会给你几乎所有的在所提供的功能conio.h
nucurses need to be installed at the first place
首先需要安装nucurses
In deb based Distros use
在基于 deb 的发行版中使用
sudo apt-get install libncurses5-dev libncursesw5-dev
sudo apt-get install libncurses5-dev libncursesw5-dev
And in rpm based distros use
在基于 rpm 的发行版中使用
sudo yum install ncurses-devel ncurses
sudo yum install ncurses-devel ncurses
For getch()
class of functions, you can try this
对于getch()
函数类,你可以试试这个
回答by Antoine Gersant
回答by karlphillip
The original conio.hwas implemented by Borland, so its not a part of the C Standard Library nor is defined by POSIX.
最初的conio.h是由 Borland 实现的,所以它不是 C 标准库的一部分,也不是由 POSIX 定义的。
But here is an implementation for Linuxthat uses ncurses to do the job.
但这里有一个 Linux 实现,它使用 ncurses 来完成这项工作。
回答by Ottavio Campana
That is because is does not exist, since it is bounded to Windows.
那是因为 is 不存在,因为它绑定到 Windows。
Use the standard functions from <stdio.h>
instead, such as getc
改用标准函数<stdio.h>
,例如 getc
The suggested ncurses library is good if you want to write console-based GUIs, but I don't think it is what you want.
如果您想编写基于控制台的 GUI,建议的 ncurses 库很好,但我认为这不是您想要的。