天天看點

C/C++有關對鍵盤輸入值的讀取函數

#include <conio.h> 

#include <stdio.h> 

void main( void ) 

 while( !_kbhit() ) //沒有鍵盤輸入kbhit ==0

{

  printf( "no input!! " ); 

if (_kbhit() )

{

 printf( "\nKey struck was '%c'\n", _getch() ); 

 }

輸出

no input!! no input!! no input!!

Key struck was 'q'

有時_kbhit() 在某些編譯平台不能用,就用kbhit()。同理 _getch()為getch()