gotoxy(int x, int y) a function available in Turbo C/C++. It is not standard C. This function is
used to move the cursor on the screen to the desire location. The top left
corner of the monitor is 0,0 and the bottom right corner might be any number
based on the size of the screen. But today's standard C++ compiler such as Visual
Studio, GCC and clang do not provide gotoxy function. However, if you are
developing console applications without a third party graphic library then gotoxy
function is useful to manage text alignment on the screen.
If you need similar
implementation on a windows machine with GCC compiler then here is an example
source code.
#include <windows.h> // header file for gotoxy
#include <iostream> //header file for standard input output
COORD coord= {0,0}; // this is global variable
void gotoxy(int x,int y)
{
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main()
{
//calling these function
int x;
gotoxy(15,5);
std::cout<<"1. This is item number one.";
gotoxy(15,7);
std::cout<<"2. This is item number two.";
gotoxy(15,9);
std::cout<<"3. This is item number three.";
gotoxy(15,11);
std::cout<<"4. This is item number four.";
gotoxy(15,13);
std::cout<<"5. This is item number five.";
std::cin>>x;
return 0;
}
Please watch the video below for detailed explanation.
Very nice code... thank a lot....
ReplyDeleteThank you!!!
ReplyDeleteIt worked!!
Exactly what i needed, thank you!!
ReplyDeleteMuchas gracias :D :D :D!!!
ReplyDeleteJust curious, for Linux and other systems that support escape sequences, do so.
ReplyDeletevoid gotoxy(int x,int y)
{
static const char *CSI = "\33["; // Esc (Escape) -> 27(10) = 33(8) = 1B(15)
printf("%s%i;%iH", CSI, x, y);
}
thanks a lot!
ReplyDeletegracias hermano, queda entendido.
ReplyDeleteThank u so much its workink.........
ReplyDeleteThank you...
ReplyDeletethank you Dinesh!
ReplyDeleteThank you
ReplyDeleteHow to increase the font size in that?
ReplyDeleteThank you
ReplyDeleteIt doesn't work for me the windows.h and stdlib.h to use gotoxy
ReplyDeletethankyou
ReplyDeleteExcellent post,this is really helpful to me.Continue sharing.
ReplyDeleteRegards,
C++ Training in Chennai | C++ programming course
Excellent post, Thanks for sharing this.
ReplyDeleteLearn more about our courses to get the best knowledge. Agile Coach Certification