C语言超难问题!!!

来源:百度知道 编辑:UC知道 时间:2024/09/28 08:05:50
如何在一个死循环中,当用户输入任意键时,就能退出该循环!!!有重谢!!!!

使用kbhit()函数
例子(来源MSDN):

/* KBHIT.C: This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/

#include <conio.h>
#include <stdio.h>

void main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );

/* Use _getch to throw key away. */
printf( "\nKey struck was '%c'\n", _getch() );
_getch();
}
----------------------------------------------------------
while(!kbhit())
{
char c;
cout<<"按任意键继续程序执行,按q按退出程序";
cin>>c;
if(c=='q')
return 1;

}

while(1)
{
if(1 == test_key)