1

I am struggling from several weeks to compile line and circle drawing codes in Windows and Ubuntu.

I am only able to compile and run simple codes such as:

Windows:

   #include <graphics.h>

int main()
{ 
   int gd = DETECT, gm;
   int x = 320, y = 240, radius;

   initgraph(&gd, &gm, "C:\\TC\\BGI");

   for ( radius = 25; radius <= 125 ; radius = radius + 20)
      circle(x, y, radius);

   getch();
   closegraph();
   return 0;
}

Linux:

#include <graphics.h>

int main()
{ 
   int gd = DETECT, gm;
   int x = 320, y = 240, radius;

   initgraph(&gd, &gm, NULL);

   for ( radius = 25; radius <= 125 ; radius = radius + 20)
      circle(x, y, radius);

   getch();
   closegraph();
   return 0;
}

I think support for some elements has been removed in latest versions of OS. Please Confirm.

genpfault
  • 51,148
  • 11
  • 85
  • 139

2 Answers2

4

I assume you are referring to the <graphics.h> header shipped by Borland for use with their compilers in 16-bit DOS.

It's basically a header from the early 1990s (that's twenty-six years ago!!). It has never been a part of C++ as we define it today (i.e. ISO standard C++, created in 1998), and has never shipped with any other compiler, such as GCC, Clang or Visual Studio.

There are no standard tools for graphics, but on Linux systems you may use GNU's ncurses library for console-based "graphics". Google or search SO for alternatives.

This is why I wish teaching institutions in certain nations would stop insisting on spreading the use of antiquated and obsolete technology, calling it "C++" without even bothering to explain the situation to their students. In my view, it's irresponsible and borderline fraudulent.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
2

This is using the "Borland Graphics Interface", which was used by Borland compilers on MS-DOS.

The original library has been obsolete for decades.

There are a couple of attempts at supporting code that uses the BGI interface on Windows named OpenBGI and WinBGI (and there may easily be others). I've never tried to use either, so I can't comment on their quality, completeness, or much of anything else beyond mere existence.

At most, I'd use such a library to port existing code to newer systems. I can't imagine writing new code using BGI today, regardless of the quality of this library.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111