macOS 下的 getch()
macOS 下的 getch() 作者: 高延( https://my.oschina.net/u/593709 ) 时间: 2020-01-14 下午 我想在c语言写的某程序实现 “按下任意键继续...”。这在windows 下好实现,用getch()就行了。 但是,macOS 用同样的办法,clang 提示找不到头文件 conio.h。 ('conio.h' file not found) 百度之,发现多种方法,比较简单的是使用 curses 库: "在linux中使用getch()函数" 这个方法在 macOS 中同样有效 代码: ... #include <curses.h> int main() { initscr(); //这行与 endwin() 成对,使用curses必须这样 ... getch(); ... endwin(); //结束 curses } 编译: clang -lcurses -o xxx xxx.c 执行: ./xxx OK,想要的结果有了,但是多出来东西了,它清屏了😳。 这不是我期待的。于是,继续百度,似乎没有简洁如此的方法了。我bing还不行吗。好的,找到某人写的 myconio, 下载解压,将myconio_mac.h 和 myconio_mac.c 复制到代码路径,引用之: ... #include <myconio_mac.h> int