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

Discussion Overview

The discussion revolves around methods for positioning characters or numbers on the screen in C++, similar to the "gotoxy" function in Pascal. It explores various libraries and approaches across different operating systems and environments, including standard C++, Unix, and GUI frameworks.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant inquires about writing characters at specific screen coordinates in C++, referencing the "gotoxy" function from Pascal.
  • Another participant notes that standard C++ lacks built-in graphics functions and suggests that the solution depends on the specific compiler and operating system being used.
  • It is mentioned that under Unix, the curses (or ncurses) library can be utilized for printing effects on a character terminal.
  • A participant provides a code snippet for using "gotoxy" in MSVC, detailing the necessary header and function implementation.
  • Another participant reiterates the use of curses for Unix and suggests GUI frameworks like Qt for positioning text in graphical applications, highlighting its cross-platform capabilities and documentation.
  • A participant shares their positive experience with Qt's event handling and its various methods for displaying text.
  • One participant expresses gratitude for the responses and indicates they will try the suggested methods.
  • A mention is made of the Borland compiler's ability to use "gotoxy" by including conio.h.
  • There is a suggestion that a flush may be needed on count as part of the implementation.

Areas of Agreement / Disagreement

Participants present multiple approaches and libraries for achieving character positioning in C++, indicating a lack of consensus on a single solution. Various opinions on the best methods and libraries are shared, reflecting differing preferences and experiences.

Contextual Notes

Participants reference specific libraries and frameworks, but the discussion does not resolve the best approach for all scenarios, as it depends on the user's environment and requirements.

Who May Find This Useful

This discussion may be useful for C++ programmers looking for methods to position text on the screen, particularly those working across different operating systems or interested in GUI development.

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
3K
  • · 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
3K