i know that there is a function call gotoxy() that moves the cursor to x,y; this is in the conio.h lib. But this won't work with the Microsoft Visual C++ compiler. Can anyone tell me how I could move the cursor to a certain spot?
Printable View
i know that there is a function call gotoxy() that moves the cursor to x,y; this is in the conio.h lib. But this won't work with the Microsoft Visual C++ compiler. Can anyone tell me how I could move the cursor to a certain spot?
Here's two functions I wrote:
Both require the window.h header file.Code:void gotoxy(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, coord);
}
//function to move the cursor n spaces horizontally:
void SetXPos(int x) {
//I made this function because I really don't like the way
//setw() does it.
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
COORD coord;
GetConsoleScreenBufferInfo(hConsole, &csbiInfo);
coord.X = x;
coord.Y = csbiInfo.dwCursorPosition.Y;
SetConsoleCursorPosition(hConsole, coord);
}
thanks!