C++ gurus and learners, we program ourselves :P all work is CC licensed

Friday, November 22

gotoxy() function in c++ by Umair Sajid

21:49 By

gotoxy() function :

The gotoxy function is used to to move the cursor to a specified location on the screen. Its Just Something Other then just Sequential Execution .It moves the cursor with respect to x axis and y axis. It is very useful when the output is to be displayed at a specified location on the screen.

Working: 

The Variable x indicates x-axis. Its Value can be from 0 to 79. The Variable y indicates the y-axis. Its Value can be from 0 to 24.

Program:

#include               // Header Files 
#include               // for getch() function 
#include               
#include             // Necessary when treating consoles  
using namespace std;
void gotoxy (int x, int y)
    {
         COORD coordinates;     // coordinates is declared as COORD
         coordinates.X = x;     // defining x-axis
         coordinates.Y = y;     //defining  y-axis
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordinates);       
    }
int main()              
{
    int x;
    int y; 
 
    cout<<"Enter x: ";
    cin>>x;
    cout<<"Enter y: ";
    cin>>y;
        
    gotoxy(x,y);     // function call 
    cout<<"C++ Clan Umair Sajid"<<endl;
    getch();
    return EXIT_SUCCESS;
}

7 comments :

  1. aah the long forgotten gotoxy() :)

    ReplyDelete
  2. Umair you did a wonderful job with this post (y)
    Also i am glad to announce that you have been one of the leading authors for past month :)
    keep it up :)

    ReplyDelete
  3. ThankYou Sir Umar ,,, This encourages me to explore c++ and find something which is intersting to me ,,,, nd my clan ( C++ Clan )

    ReplyDelete
  4. Actually we are making ludo project so ,,,, i think this is something helpful :) :)

    ReplyDelete
  5. You know it's built-in in conio.h ?? but deprecated in visual studio.

    ReplyDelete