gotoxy() in a Windows Console


Match word(s).

If you have any questions or comments,
please visit us on the Forums.

FAQ > How do I... (Level 2) > gotoxy() in a Windows Console

This item was added on: 2003/02/09

C and C++ standards attempt to be generic as far as operating systems go, leaving the common functions available for screen manipulation rather limited. This means you have to resort to looking at your compiler's documentation when you want to do something so "simple" as go to a specific pair of co-ordinates on the screen.

Here's a simple Windows Console version of gotoxy(). You might find that this function already exists in you compiler, so watch out for conflicts.


#include <windows.h> 

void gotoxy(int x, int y)
{
  COORD coord;
  coord.X = x;
  coord.Y = y;
  SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

Script provided by SmartCGIs