Skip to content
Sign upLog in
← Back to Community

C++ Equivalent to Turbo C++'s "gotoxy" function

Profile icon
ferweja

In Turbo C++, the gotoxy functions was used to position the cursor on a text output screen to whatever coordinates it was given.

Visual C++ had no such function, so I created this code to accomplish the same thing:

#include

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

How can I do this in Repl.it C++? I need to be able to position the cursor anywhere on the text output screen without clearing the screen. (I'm a teacher and trying to get this for my students to use.)

Thanks in advance!

Voters
Profile icon
Stefano-luislui
Profile icon
ferweja
Comments
hotnewtop
Profile icon
programmeruser

Turbo C++ is horribly outdated, and this is Linux not Windows. Use ANSI escape codes:

#include <iostream> void gotoXY(int x, int y) { std::cout << "\x1b[" << x << ";" << y << "H" }

Next time ask your questions in the ask section not the tutorials section.