Reputation: 3
I am kinda new to C++ and i was wondering if is there any way to get the Console's Cursor position (x, y)?
For example, In C# i can use:
Console.CursorLeft for X and Console.CursorTop for Y
Upvotes: 0
Views: 1433
Reputation: 25388
If you are on Windows, you can do this (error handling omitted for brevity):
HANDLE hConsoleOutput = GetStdHandle (STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi = { };
BOOL ok = GetConsoleScreenBufferInfo (hConsoleOutput, &csbi);
The current cursor position should then be in csbi.dwCursorPosition
;
On Unix platforms, you would use the ncurses library.
Upvotes: 2