(原創) 如何在curses中使用getch()? (OS) (Linux) (C/C++) (C)
getch()原來在<stdio.h>,但現在只有在<curses.h>提供,需配合curses的寫法。
1
/*
2
(C) OOMusou 2006 http://oomusou.cnblogs.com
3
4
Filename : curses_getch.cpp
5
Compiler : gcc 4.1.0 on Fedora Core 5
6
Description : Demo how to use getch() in curses & convert () to bool
7
Release : 11/28/2006
8
*/
9
10
#include <curses.h> // use ncurses, initscr(), noecho(), getch(), printw(), endwin()
11
#include <stdlib.h> // exit(), EXIT_SUCCESS
12
13
int 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.com3

4
Filename : curses_getch.cpp5
Compiler : gcc 4.1.0 on Fedora Core 56
Description : Demo how to use getch() in curses & convert () to bool7
Release : 11/28/20068
*/9

10
#include <curses.h> // use ncurses, initscr(), noecho(), getch(), printw(), endwin() 11
#include <stdlib.h> // exit(), EXIT_SUCCESS 12

13
int main() {14
// Initialize curse scheme 15
initscr(); 16
// no echo in curse17
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
}


浙公网安备 33010602011771号