Results 1 to 3 of 3

Thread: moving the cursor (c++)

  1. #1

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238

    moving the cursor (c++)

    i know that there is a function call gotoxy() that moves the cursor to x,y; this is in the conio.h lib. But this won't work with the Microsoft Visual C++ compiler. Can anyone tell me how I could move the cursor to a certain spot?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Here's two functions I wrote:

    Code:
    void gotoxy(int x, int y) {
    
        COORD coord;
        coord.X = x;
        coord.Y = y;
    
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleCursorPosition(hConsole, coord);
    
    }
    
    //function to move the cursor n spaces horizontally:
    void SetXPos(int x) {
    
        //I made this function because I really don't like the way
        //setw() does it.
    
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
        COORD coord;
    
        GetConsoleScreenBufferInfo(hConsole, &csbiInfo);
    
        coord.X = x;
        coord.Y = csbiInfo.dwCursorPosition.Y;
    	
        SetConsoleCursorPosition(hConsole, coord);
    }
    Both require the window.h header file.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width