C++在指定位置输出数字(kbhit()按下键的时候返回非零值,没按下键的时候返回0,即false)
作者:互联网
#include <iostream>
#include<ctime>
#include<cstdlib>
#include<conio.h>
#include<windows.h>
using namespace std;
class Timer
{
private:
int n;
public:
void gotoxy(int x,int y)
{
HANDLE h;
COORD c;
c.X=x;
c.Y=y;
h=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h,c);
}
Timer()
{
n=100;
}
void timer()
{
// time_t t;//无符号整数类型
while(true)
{
if(kbhit())
break;
else
{
gotoxy(30,10);
cout<<n;
n++;
}
Sleep(1000);
}
}
};
int main()
{
Timer t;
t.timer();
return 0;
}
标签:返回,false,int,void,下键,gotoxy,kbhit,HANDLE,include 来源: https://blog.csdn.net/qq_43312665/article/details/88375189