Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Gotoxy in C++

  1. Jan 18, 2008 #1
    Is there a way I can write characters or numbers anywhere on the screen in C++ like the ones used in pascal like gotoxy where I simply write screen coordinates as x & y.
  2. jcsd
  3. Jan 18, 2008 #2


    User Avatar

    Staff: Mentor

    Standard C++ doesn't have graphics functions "built into" it. You have to use an add-on library which is usually tailored for a particular operating system. Your particular version of C++ may come with such a library, but we can't tell you how to use it unless we know which one it is! :frown:

    So, tell us which C++ compiler you're using and whether you're using Windows, MacOS or whatever, and maybe someone can help.
  4. Jan 18, 2008 #3


    User Avatar
    Science Advisor
    Homework Helper

    Under unix there is a library called curses (or ncurses in newer versions) to do printing effects on a character terminal.
    Under a GUI it would depend on what platform but most have the ability to write text at a particular coordinate in a window, or you could use something like OpenGL.
  5. Jan 18, 2008 #4
    for msvc its:
    #include <windows.h>
    void gotoxy(int x, int y)
    COORD coord;
    coord.X = x; coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

    http://msdn2.microsoft.com/en-us/library/ms686025.aspx" [Broken]
    Last edited by a moderator: May 3, 2017
  6. Jan 18, 2008 #5
    for GUI in c++ i recommend Qt, it's way of handling events is the best I've seen so far, and it works flawlessly on windows, Linux, and macs... thats the only platforms i programmed for, but it lists many more OS's.
    for outputting text with Qt, you can use the QTextEdit widget, create QLabels anywhere on the window, or create you own display widget and render it using either OpenGL (using QGLWidget) or QPainter....

    I really love the Qt documentation, it's full of really good examples and tutorials, and the classes all have great descriptions and examples per function...
  7. Jan 18, 2008 #6
    wow, tnks for all the reply will try that.
  8. Jan 19, 2008 #7


    User Avatar
    Gold Member

    In the Borland compiler you can include conio.h and then you can use gotoxy like pascal.
  9. Jan 28, 2008 #8
    you might need to use a flush on cout too.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook