4

这些天我在 Ubuntu 上工作。当我使用 gcc 编译我的 C 程序时,它给出的错误conio.h不存在。我想使用clrscr()getch()功能。你能告诉我这个头文件在linux中的替代品吗?

4

8 回答 8

3

getch()功能可以在curses.h(库“curses”)中找到。同一个库提供了清除屏幕的功能。查看这些链接:

http://linux.die.net/man/3/getch

http://linux.die.net/man/3/erase

于 2012-08-06T07:15:32.423 回答
2

system("clear");可以在linux中使用,而不是clrscr();

于 2015-01-13T08:35:00.030 回答
2
# include <curses.h>

       int erase(void);
       int werase(WINDOW *win);
       int clear(void);
       int wclear(WINDOW *win);
       int clrtobot(void);
       int wclrtobot(WINDOW *win);
       int clrtoeol(void);
       int wclrtoeol(WINDOW *win);

DESCRIPTION
       The erase and werase routines copy blanks to every position in
       the window, clearing the screen.

我猜这个问题一再被否决,因为它意味着对基本 C 语言功能的理解不足和/或 OP 只是将代码复制/粘贴到编辑器/IDE 中。

同样,只需system("exit");在您的代码中使用:

#include<stdlib.h>
main()
{
system("clear"); //clears the screen
} 

检查手册页显示:

SYSTEM(3)                                 Linux Programmer's Manual   SYSTEM(3)

NAME
       system - execute a shell command

SYNOPSIS
       #include <stdlib.h>

       int system(const char *command);

DESCRIPTION
       system() executes a command specified in command by calling /bin/sh -c 
command, and returns after the command has been completed.  
During execution of the command, SIGCHLD will be blocked, and SIGINT
and SIGQUIT will be ignored.

也可能是这个问题可能与以下问题重复:

最后,请查看以下内容以获取更多详细信息和示例:

于 2015-10-02T17:29:15.273 回答
0

显然你没有尝试谷歌搜索。

没有直接的替代方案。

这篇博文:http ://wesley.vidiqatch.org/code-snippets/alternative-for-getch-and-getche-on-linux/为您提供了getch()getche()

或者,您可以使用 libncurses 做您想做的事:http: //tech.dir.groups.yahoo.com/group/linux/message/29221

于 2012-08-06T07:16:30.533 回答
0

curses.h 是 conio.h 的替代品。安装 build-essentials 并安装 libncurses5-dev。

然后你可以使用这些功能。[http://ubuntuforums.org/showthread.php?t=880601][1]

于 2013-06-30T13:25:52.777 回答
0

在 G++ 编译器中,我们使用头文件system("clear")中定义的函数stdlib.h

#include<iostream>
#include<stdlib.h>

int main() {
  std::cout<<"Hello Aliens:";
  system("clear");
}
于 2018-03-27T01:36:56.243 回答
0

我正在修改一些代码;安装 ncurses 后,我插入了以下代码:

#include <stdio.h>
#include <ncurses.h>

main ()
{

system ("clear");
getchar ();

}
于 2016-07-03T17:29:26.923 回答
0

还有另一种方法可以通过 C 代码而不是系统调用来完成。

void clrscr(void) {
  fprintf(stdout, "\033[2J\033[0;0f");
  fflush(stdout);
}

我很久以前就找到了它,并且我已经成功地在 raspbian 上检查了它。

并且:

void gotoxy(int x, int y) {
  printf("%c[%d;%df",0x1B, y, x);
}

我希望它对你有帮助。

问候。

于 2017-01-10T14:28:23.593 回答