看板 LinuxDev 關於我們 聯絡資訊
作者: qrtt1 (thinking in java) 看板: C_and_CPP 標題: Re: [問題] 如何不需要按enter而得到字元? 時間: Thu Sep 15 19:57:35 2005 ※ 引述《tomex (tomex_ou)》之銘言: : 在c++中,無論使用 cin.get()或 getchar() : 它都需要按enter後,才能得到字元,實在是#@#$@#$... : 在linux中, : 我想在程式結尾按某key就直接離開程式,否則什麼都不要動 : 該如何達到呢? [slayer@rat testZone]$ cat getch.c #include <curses.h> int main(){ getch(); } [slayer@rat testZone]$ gcc getch.c /var/tmp//cc6NtuYJ.o: In function `main': /var/tmp//cc6NtuYJ.o(.text+0x15): undefined reference to `stdscr' /var/tmp//cc6NtuYJ.o(.text+0x1a): undefined reference to `wgetch' [slayer@rat testZone]$ gcc getch.c -lncurses [slayer@rat testZone]$ ps. 這樣是不夠的 :) [slayer@rat testZone]$ ./a.out Segmentation fault (core dumped) [slayer@rat testZone]$ cat getch.c #include <curses.h> int main(){ /* initscr is normally the first curses routine to call when initializing a program. */ initscr(); getch(); /* A program should always call endwin before exiting or escaping from curses mode temporarily. */ endwin(); } [slayer@rat testZone]$ gcc getch.c -lncurses [slayer@rat testZone]$ -- 相關資料可以man curses ps. 弟在freebsd上測試的,如果您有用到更多相關的函式 會與linux有點不同 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.59.94.118 ※ 編輯: qrtt1 來自: 210.59.94.118 (09/15 19:58) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.26.34.248