(原創) 如何在curses中使用getch()? (OS) (Linux) (C/C++) (C)
getch()原來在<stdio.h>,但現在只有在<curses.h>提供,需配合curses的寫法。
1/*
2(C) OOMusou 2006 http://oomusou.cnblogs.com
3
4Filename : curses_getch.cpp
5Compiler : gcc 4.1.0 on Fedora Core 5
6Description : Demo how to use getch() in curses & convert () to bool
7Release : 11/28/2006
8*/
9
10#include <curses.h> // use ncurses, initscr(), noecho(), getch(), printw(), endwin()
11#include <stdlib.h> // exit(), EXIT_SUCCESS
12
13int main() {
14 // Initialize curse scheme
15 initscr();
16 // no echo in curse
17 noecho();
18
19 char c;
20 while(c = getch()) {
21 printw("%c\n",c);
22 }
23
24 // end curses scheme
25 endwin();
26 exit(EXIT_SUCCESS);
27}
2(C) OOMusou 2006 http://oomusou.cnblogs.com
3
4Filename : curses_getch.cpp
5Compiler : gcc 4.1.0 on Fedora Core 5
6Description : Demo how to use getch() in curses & convert () to bool
7Release : 11/28/2006
8*/
9
10#include <curses.h> // use ncurses, initscr(), noecho(), getch(), printw(), endwin()
11#include <stdlib.h> // exit(), EXIT_SUCCESS
12
13int main() {
14 // Initialize curse scheme
15 initscr();
16 // no echo in curse
17 noecho();
18
19 char c;
20 while(c = getch()) {
21 printw("%c\n",c);
22 }
23
24 // end curses scheme
25 endwin();
26 exit(EXIT_SUCCESS);
27}