能夠定位光標位置,改變屏幕設置
#include <iostream>#include <windows.h>#include <conio.h>#include <stdlib.h> //system函數所需頭文件#define stoptimelong 500 //Sleep函數以毫秒為單位,Sleep(500);表示停半秒using namespace std; //跳到屏幕指定坐標 void gotoxy(int x,int y){ CONSOLE_SCREEN_BUFFER_INFO csbiInfo; HANDLE hConsoleOut; hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo); csbiInfo.dwCursorPosition.X = x; csbiInfo.dwCursorPosition.Y = y; SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);} int main(void){ int x=14, y=5; gotoxy(x, y); printf("你好!"); Sleep(stoptimelong); system("color 10"); //調用控制臺顏色管理命令,可以改變屏幕和字體的顏色 printf("歡"); Sleep(stoptimelong); printf("迎"); Sleep(stoptimelong); printf("來"); Sleep(stoptimelong); printf("到"); system("color 19"); Sleep(stoptimelong); printf("計"); Sleep(stoptimelong); printf("算"); Sleep(stoptimelong); printf("機"); system("color 37"); Sleep(stoptimelong); printf("冒"); Sleep(stoptimelong); printf("險"); system("color 46"); Sleep(stoptimelong); printf("世"); Sleep(stoptimelong); printf("界"); Sleep(stoptimelong); printf("!"); Sleep(stoptimelong); cout<<endl; getch(); return 0;}
演示圖片
以上所述就是本文的全部內容了,希望能夠對大家學習C++有所幫助。
新聞熱點
疑難解答
圖片精選