Using Gotoxy in C++ for Positioning Characters on Screen

  • Context: C/C++ 
  • Thread starter Thread starter chrisalviola
  • Start date Start date
  • Tags Tags
    C++
Click For Summary
SUMMARY

This discussion focuses on positioning characters on the screen in C++ using the gotoxy function, similar to Pascal. Standard C++ lacks built-in graphics functions, necessitating the use of external libraries such as ncurses for Unix systems or Windows-specific functions like SetConsoleCursorPosition. For GUI applications, the Qt framework is recommended for its robust event handling and cross-platform capabilities, allowing developers to position text using QTextEdit or QPainter. The Borland compiler also supports gotoxy through conio.h, providing an alternative for those using that environment.

PREREQUISITES
  • Familiarity with C++ programming
  • Understanding of Windows API functions, specifically SetConsoleCursorPosition
  • Knowledge of the Qt framework for GUI development
  • Basic understanding of Unix terminal libraries, particularly ncurses
NEXT STEPS
  • Explore the Qt framework documentation for GUI text positioning techniques
  • Learn about the ncurses library for character terminal graphics in Unix
  • Investigate the Windows API for console applications and cursor manipulation
  • Study the use of OpenGL with Qt for advanced rendering techniques
USEFUL FOR

Developers working with C++ who need to position text on the screen, including game developers, GUI application developers, and those transitioning from Pascal to C++. This discussion is particularly beneficial for those using Windows or Unix systems.

chrisalviola
Messages
80
Reaction score
0
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.
 
Technology news on Phys.org
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.
 
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.
 
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"
 
Last edited by a moderator:
mgb_phys said:
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.

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... that's 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...
 
wow, tnks for all the reply will try that.
 
In the Borland compiler you can include conio.h and then you can use gotoxy like pascal.
 
you might need to use a flush on count too.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 24 ·
Replies
24
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K