Thread: I just want a cursor locator..

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    3

    I just want a cursor locator..

    I've used a few simple languages in the past, such as the educational Turing language, Delphi, and BASIC, but in C++ I am having a simple problem: I can not find a function that will allow me to place my cursor on the screen.

    Going into my ancient Borland Turbo C++, I found that in the conio.h library there is a gotoxy(int,int) function. This would have been great, but Dev-C++ doesn't seem to recognise its existence.

    I'd just check Dev-C++'s function listing, but it's missing from the help file.

    The function isn't listed in the function listing of this site, but there are references to it in a few simple resources.

    I'm relatively new to C++, and in order to build familiarity, I'm wishing to make a few simple text-graphic games, which I would need locations for.

    All I need, is the function, and the library. Any help would be appreciated greatly.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    AFAIK, there is no porable way to do that... besides using a bunch of spaces, newlines, and backspaces...

    there was some non-standard library that somebody pointed out to me, but the name of it escapes me at the moment...

    fake-edit: curses/ncurses... something like that... ?

    real-edit: Dev-C++ uses the GCC compiler, which is pretty standards-compliant. there's a good reason the Dev-C++ team didn't include that function.

    real-edit2: generally, if you're making a text-graphic game, just use good ol' ascii art and redraw the screen when you need to modify something... there really arent any good ways to do that either, besides scrolling the characters off teh screen... but you could thow in a function like this:
    Code:
    #include<cstdlib>
    ...
    void clearscrn()
    {
        system("cls");  //change 'cls' to 'clear' for linux
    }
    and call clearscrn() whenever you need it.
    Last edited by major_small; 07-03-2005 at 06:30 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    3
    Then, why would Borland's team have shown it as part of the conio.h standard output formatting functions?

    I have Borland TCPP 3.0 - and it's listed as one of 38 conio functions, along with clrscr and kbhit.

    Was the library just completely revamped not to include this function?

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    because they decided to include that... borland isn't the standards committee... IEEE is (part of) the standards committee. compilers don't have to follow the standards--in fact most of them don't strictly adhere to standards.

    if you want to find out if a function is standard, you can either get a copy of the standard, or just visit http://cppreference.com <--AFAIK, they only have information on standard functions,flags,etc.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> Then, why would Borland's team have shown it as part of the conio.h standard output formatting functions?
    There's nothing standard about "conio.h". That's an old Borland specific header that you can't expect on any other compiler.

    If you want to manipulate the console, you'll have to use the Win32 API directly or find a library that does it for you. It just so happes that Dev-C++ provides a "conio" library that emulates the old Borland API's. Look for "conio.h" and "conio.c" in your include directory. You may have to download it in a dev-pack as described here: http://molhanec.net/devcpphelp/packages.html

    If you want to go the direct Win32 API route, there's a great tutorial here: http://www.adrianxw.dk/SoftwareSite/...Consoles1.html

    gg

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    A quickie gotoxy for Win Console.

    Regards,
    Brian

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    void gotoxy( int x, int y ) 
    { 
       COORD cur = { x, y }; 
       SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), cur ); 
    }
    
    int main(int argc, char * argv[] )
    {
    	gotoxy( 6, 6 );
    	cout << "Line 1";
    	gotoxy( 2, 2 );
    	cout << "Line 2";
    	gotoxy( 0, 0 );
    	cout << "Line 3";
    	
    	gotoxy( 4, 4 );
    	cout << "Press `Enter' to continue . . . ";
    	
    	cin.sync( );
    	cin.ignore( );
    	return(0);
    }

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    3
    Well, as you can tell - I'm completely new to C++.

    I saw that answer in the FAQ, about the COORD, and since it didn't make sense and I knew I was making a DOS console, I didn't connect it to think of it being a Windows based Console. Thus, I never even tried it, considering it to not be what I needed.

    Now I know, thank you. Everyone.

Popular pages Recent additions subscribe to a feed