How can C++ be used to write a program with an interface and not in the terminal?

In principle, this cannot be because the standard C++ language has no functionality to create a comprehensive interface.And not at all to create a comprehensive graphical interface.Before that, you depend on libraries made by others, which often depend on the platform you are developing for.

Currently there is a graphical standard to the Genesis called OpenGL.This is a hardware-dependent API supported by most graphics card manufacturers. That means you can develop code that matches the drivers for these cards regardless of which operating system is used. Linux, Windows, MacOS… Does nothing more.

(There are still alternatives, but they are again dependent on the operating system.)

Only, OpenGL is an ANSI C API by default and not C++.That makes the use more difficult but there are many who meanwhile call the C API within C++ wrappers so that you can use beautiful C++ classes. This means that you have to choose between the many libraries to find what best suits what you need.

In addition to OpenGL, modern operating systems also have their own API to handle all graphical interaction.The WINDOWS API, for example, contains a huge amount of features to create windows with and within it all sorts of buttons, fields, labels and other things.They can also be used and although this is also an ANSI C API, various wrappers are also available to apply it from C++ through classes. Microsoft has also developed .NET and in principle it is possible to write .NET applications in C++ if you want. (But C# is more convenient.)

But as mentioned, the C++ standard has no graphical functionality.Only terminal logic.

However, it is possible to create a complete interface via a terminal instead of scrolling line by line.This stems from the early UNIX era and has to do with ANSI Escape codes.Certain characters within the terminal have a special function. If you use it, it will not display any characters on the screen but perform another screen action. For example, there are standard ANSI characters for moving the cursor or for hate hearing a bell. The escape codes are slightly more complex because you then use the escape character followed by other characters for a more specific task, provided the terminal supports it. This may have to do with adjusting the color, placing the cursor at an exact position or to erase the screen.

The Game NetHack makes a lot of USE of ANSI codes.It is written in C as C++ officially did not exist when NetHack was made. But it is a nice example of a user interface in terminal (or console) mode. This project was supported by various different operating systems and is a good example of the challenges you face when you want to program platform-Independent…

Leave a Reply