c++ 控制while循环,任意键暂停,任意键继续
#include <iostream>
#include <ctime>
#include <conio.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
int main()
{
while(1){
if (_kbhit()){//如果有按键按下,则_kbhit()函数返回真,头文件conio.h
getch();//键盘输入,不会显示
getch();
}
cout << rand()%3+22 << " ";//产生22到24间的随机数,头文件cstdlib
Sleep(1000);//隔一秒输出一个,window.h
}
return 0;
}
}
while(1){
if (_kbhit()){//如果有按键按下,则_kbhit()函数返回真,头文件conio.h
getch();
getch();
}
.....
}