#includewindows
void gotoxy(int x, int y)函數
{文檔
COORD coord;input
coord.X = x;coord.Y = y;it
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);io
}編譯
#include <windows.h>
void gotoxy(int x, int y)//x爲列座標,y爲行座標
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}變量
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);error
這些是windows裏自帶地規範函數,您可以去幫助文檔裏看看di
HANDLE GetStdHandle(
DWORD nStdHandle // input, output, or error device
);
BOOL SetConsoleCursorPosition(
HANDLE hConsoleOutput, // handle to screen buffer
COORD dwCursorPosition // new cursor coordinates
);
coord 頭文件:windows.h void goto_xy(int x,int y) { HANDLE hOut; COORD pos={0,0}; hOut = GetStdHandle(STD_OUTPUT_HANDLE); //pos = {x,y};這一句編譯不經過 pos.X=x; pos.Y=y; SetConsoleCursorPosition(hOut,pos); } 這樣用戶就自定義了一個在VC++6.0中實現控制光標所在位置的函數 COORD pos; 這一句定義了一個結構體變量pos,它的兩個成員是X和Y