How can I set the cursor at the desired location on the console in C or C++?
I remember a function called gotoxy(x,y)
, but I think its deprecated. Is th
I use a really simple method. You don't overly need to know what a HANDLE is unless you're really diving into console applications, a COORD object is in the windows.h standard library and has two member data intergers X and Y. 0,0 is the top left corner and Y increases to go down the screen. You can use this command and just continue to use std::cout<< to print whatever you need.
#include
int main(void){
//initialize objects for cursor manipulation
HANDLE hStdout;
COORD destCoord;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
//position cursor at start of window
destCoord.X = 0;
destCoord.Y = 0;
SetConsoleCursorPosition(hStdout, destCoord);
}