關於Linux之curses.h文件

—> conio.h文件,一般用來實現getch()功能 —> 即讀取鍵盤字符但是不顯示出來
—> 在Windows環境中能編譯通過。但在Linux環境下編程,conio.h文件無法編譯通過,因爲Linux沒有這個頭文件,而用另一個頭問價代替:

#include <curses.h>

這個頭文件依賴libncurses5-dev,終端下載:

sudo apt-get install libncurses5-dev

貼上這個頭文件的內容:

/*---------in linux---------*/
#include<stdio.h>
int main()
{
    char c;

    printf("Input a char:");
    system("stty -echo");           //不顯示輸入內容
    c=getchar();
    system("stty echo");
    printf("You have inputed:%c \n",c);

    return 0;
}
/*---------in windows---------*/
#include <stdio.h>
#include <conio.h>
int main()
{
    char c;

    printf("Input a char:");
    c=getch();
    printf("You have inputed:%c \n",c);

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章