將光標放到任意的位置ios
void gotoxy(int x,int y)//位置函數 { COORD pos; pos.X=x; pos.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); }
實現讓文字顯示一段時間後消失windows
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(); }