<conio.h>时Console IO控制台输入输出的简写,定义了许多通过控制台进行数据输入输出的函数
该头文件仅在windows平台下提供,unix和linux下不包含该头文件
(linux下可以下载兼容包libconio-1.0.0,编译的时候连接动态库 -lconio,但没有意义,不如用标准输入输出函数)
该库包含的常用函数如下
char _getch(void); 从输入缓冲区读取一个字符,不会显示在屏幕上
char _getche(void); 从输入缓冲区读取一个字符,显示在屏幕上
int _kbhit(void); 检测是否有键盘输入,如果有则返回非零值,没有则返回0。
范例:
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char ch;
ch = _getch();
printf("\nYou entered: %c\n", ch);
system("pause");
return 0;
}
范例:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int count = 0;
printf("Press any key to start counting...\n");
while (!_kbhit())
{
printf("%d ", count);
count++;
}
printf("\nA key is pressed. Counting stopped.\n");
system("pause");
return 0;
}