how can I move the X position with gotoxy() without changing the Y position?
Printable View
how can I move the X position with gotoxy() without changing the Y position?
X position of?
the X position where cout prints stuff..
I wrote this code last semester at school because I didn't dig how setw() managed things:
Hope this helps.Code:#include <windows.h>
//function to move the cursor x spaces horizontally:
void SetXPos(int x) {
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);
}
gotoxy is Borland-specific. I hope you know that.
But it can be recreated easily:
Code:void gotoxy(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(hConsole, coord);
}
hmm, so is conio.h borland specific or something?
No, not really. Nearly every compiler has conio.h. But the contents are not standardized and vary greatly from compiler to compiler.
The "standard" way of doing this is with ncurses, but I don't know if there's a Windows port of it. Take a look :)