c語言中 gotoxy() 函式的使用
阿新 • • 發佈:2018-11-20
轉自 https://blog.csdn.net/radjedef/article/details/79028329
#include <stdio.h> #include <windows.h> void gotoxy(int x, int y) { COORD pos = {x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 獲取標準輸出裝置控制代碼 SetConsoleCursorPosition(hOut, pos);//兩個引數分別是指定哪個窗體,具體位置 } int main() { int x,y; gotoxy(2,2); printf("hello,world!"); system("pause"); return 0; }
其實我在是在需要的時候才用的它,寫這個也是為了讓看到這篇文章的朋友在不必深入瞭解它的前提下,可以使用gotoxy();
引用百度文庫中對coord的解釋說:
COORD是Windows API中定義的一種結構,表示一個字元在控制檯螢幕上的座標。其定義為:
typedef struct _COORD {
SHORT X; // horizontal coordinate
SHORT Y; // vertical coordinate
} COORD;
- x,y就是在使用gotoxy後游標所在的位置 ,而後面的兩句
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos);