C++ 得到光标坐标和移动光标
C++ 得到光标位置 和 移动光标,网上转的。
void appGetXY() { HANDLE hStdout; CONSOLE_SCREEN_BUFFER_INFO pBuffer; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hStdout, &pBuffer); cout << pBuffer.dwCursorPosition.X << pBuffer.dwCursorPosition.Y <<endl;; }
void appGotoXY(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); }