coord

COORD是Windows API中定義的一種結構,表示一個字元在控制台螢幕上的坐標。其定義為: typedef struct _COORD SHORT X; // horizontal coordinate SHORT Y; // vertical coordinate COORD;

定義

typedef struct _COORD {

SHORT X; // horizontal coordinate
SHORT Y; // vertical coordinate
} COORD;

性質

表示一個字元在控制台螢幕上的坐標。

套用

c++中的例子:

#include <iostream>

#include <Windows.h>

using namespace std;

void gotoxy(int x,int y)

{

COORD loc={x,y};

HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(hOutput,loc);

}

int main()

{

gotoxy(2,0);

cout<<"Hello World!"<<endl;

system("pause");

return 0;

}

=============輸出結果為(下劃線表示此處無字元,)==============

__Hello World!

請按任意鍵繼續...

==========================================================

C中的例子:

void Pos(int x, int y)

{

COORD pos;

HANDLE hOutput;

pos.X = x;

pos.Y = y;

hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(hOutput, pos);

}

相關詞條

相關搜尋

熱門詞條

聯絡我們