将光标放到任意的位置

void gotoxy(int x,int y)//位置函数
{
    COORD pos;
    pos.X=x;
    pos.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

 

实现让文字显示一段时间后消失

for(int i=1;i<=10;i++){
        gotoxy(i,1);
        printf("%d ",i);
        Sleep(1000);
        system("cls");//清屏
    }

实现限时输入

 

#include <iostream>
#include <cstdio>
#include <windows.h>
#include<ctime>
#include <conio.h>

using namespace std;

char in() {
    char a;
    time_t timeBegin = time(0);
    int n=0;
    while(true)  {           //the main loop  ||  主循环
        if(kbhit()){       //detect the keyboard  ||  kbhit检测键盘输,如果发现了输入
            a = _getch() ;
            return a;
        } else if(time(0)-timeBegin==4 && n==0) {
            cout << "Your time have "<<3 <<" s"<< endl;//输出倒计时
            n=1;
        }
        else if(time(0)-timeBegin==5 && n==1) {
            cout <<  "Your time have "<<2<<" s"<< endl;//输出倒计时
            n=2;
        }
        else if(time(0)-timeBegin==6 && n==2) {
            cout << "Your time have "<<1 <<" s"<< endl;//输出倒计时
            n=3;
        }
        else if(time(0)-timeBegin>=7){//时间过去30秒,进行其他操作
            timeBegin = time(0);
            n=0;break;
//调用其他方法进行其他操作
        }
    }
}
int main(){
    cout<<in();
}