如下代码所示
用到了 kbhit 函数,但是我这个程序运行起来我还没有输入f 他就直接给执行了,不知道时什么问题
#include<iostream>
#include<Windows.h>
#include<conio.h>
using namespace std;
bool test()
{
while (kbhit)
{
char userInput = getch();
if (userInput =='f')
{
return true;
}
else
{
return false;
}
}
}
int main()
{
while (true)
{
if (test)
{
cout << "你点击了f,程序结束" << endl;
return 0;
}
cout << "程序正在运行!" << endl;
Sleep(1000);
}
system("pause");
return 0;
}