linux下c中getchar和CLRSC()的替代
这些天我在Ubuntu上工作。当我使用gcc编译我的C程序时,它给出了错误linux下c中getchar和CLRSC()的替代,c,linux,C,Linux,这些天我在Ubuntu上工作。当我使用gcc编译我的C程序时,它给出了错误conio.h不存在。 我想使用clrsc()和getch()函数。 你能告诉我这个头文件在linux中的替代品吗。可以在curses.h(库“curses”)中找到getch()函数。同一个库提供了清除屏幕的功能。查看以下链接: 显然你没有尝试谷歌搜索 没有直接的选择 这篇博文:为您提供了getch()和getche() 或者,您可以使用libncurses做您想做的事情:curses.h是conio.h的替代品。 安
conio.h
不存在。
我想使用clrsc()
和getch()
函数。
你能告诉我这个头文件在linux中的替代品吗。可以在curses.h
(库“curses”)中找到getch()
函数。同一个库提供了清除屏幕的功能。查看以下链接:
显然你没有尝试谷歌搜索 没有直接的选择 这篇博文:为您提供了
getch()
和getche()
或者,您可以使用libncurses做您想做的事情:curses.h是conio.h的替代品。 安装build essentials并安装libncurses5-dev 然后您可以使用这些函数。 [http://ubuntuforums.org/showthread.php?t=880601][1]
系统(“清除”)
可以在linux中使用,而不是clrsc()代码>
检查手册页显示:
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.
系统(3)Linux程序员手册系统(3)
名称
系统-执行shell命令
提要
#包括
int系统(常量字符*命令);
描述
system()通过调用/bin/sh-c执行命令中指定的命令
命令,并在命令完成后返回。
在命令执行期间,SIGCHLD将被阻止,SIGINT
SIGQUIT将被忽略。
该问题也可能是以下问题的重复:
最后,查看以下内容以了解更多细节和示例:
我正在修补一些代码;安装ncurses后,我插入了以下代码:
#include <stdio.h>
#include <ncurses.h>
main ()
{
system ("clear");
getchar ();
}
#包括
#包括
主要()
{
系统(“清除”);
getchar();
}
还有另一种方法可以通过C代码而不是系统调用来实现
void clrscr(void) {
fprintf(stdout, "\033[2J\033[0;0f");
fflush(stdout);
}
我很久以前就找到了,我已经在拉斯宾身上成功地查过了
而且:
void gotoxy(int x, int y) {
printf("%c[%d;%df",0x1B, y, x);
}
我希望它能帮助你
关于。在G++编译器中,我们使用在stdlib.h
头文件中定义的system(“clear”)
函数
#include<iostream>
#include<stdlib.h>
int main() {
std::cout<<"Hello Aliens:";
system("clear");
}
#包括
#包括
int main(){
std::coutCheck out the library。我相信cursesgetch()
函数可能重复,只有在调用initscr()
后才能使用,该函数控制(文本)屏幕。我正在尝试诅咒。h而且在我的ubantu o.sHave上也找不到它。您尝试在存储库中定位它?如果您不知道如何定位,请尝试askubuntu.com。
void gotoxy(int x, int y) {
printf("%c[%d;%df",0x1B, y, x);
}
#include<iostream>
#include<stdlib.h>
int main() {
std::cout<<"Hello Aliens:";
system("clear");
}