1

I tried compiling code using several IDEs of C++ using "graphics.h" header file using the list in TechGeekBuzz: Best C++ Online Compiler but they flag the error

1:21: fatal error: graphics.h: No such file or directory

The program I am trying to run is

#include<graphics.h>
#include <conio.h>
int main()
{
    int gd = DETECT, gm;
    initgraph(&gd,&gm, "C:\\tc\\bgi");
    circle(300,300,50);
    closegraph();
    getch();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Hilary Diaz
  • 39
  • 1
  • 6
  • 3
    Because graphics.h is not a standard header file. AFAIK it's a Windows header file and most online IDEs use Linux so you will get the same problem with conio.h – Thomas Sablik Jan 12 '20 at 13:27
  • 2
    Why would you expect `graphics.h` to be supported? – KamilCuk Jan 12 '20 at 13:35
  • 4
    Because it has been obsolete for over 20 years. – Jesper Juhl Jan 12 '20 at 13:37
  • 4
    It is an olden 16-bit real-mode DOS library, included with Borland's Turbo C and C++ products. It worked by directly writing into the graphics adapter's memory, the kind of crime against humanity that was common in the early PC days before protected-mode operating systems became standard. Emulator libraries have been written that work on a modern OS, the one provided by the University of Colorado is a top google hit. Online compilers won't know anything about them. – Hans Passant Jan 12 '20 at 13:55
  • @ThomasSablik -- it's not Windows. As mentioned in another comment, it comes from Borland's products, and was adapted by other compiler vendors at the time. Strictly DOS, as was conio.h. – Pete Becker Jan 12 '20 at 17:34
  • There are a couple ports: https://github.com/SagarGaniga/Graphics-Library and https://github.com/rafiulgits/BGI-Projects/tree/master/Graphics%20in%20CodeBlocks for example – Jerry Jeremiah Nov 06 '20 at 00:09

1 Answers1

6

You should only expect the standard headers to be available in online compilers. Some (but not all) also provide posix headers or very popular libraries such as boost.

Neither <graphics.h> nor <conio.h> are standard headers. Both are old MSDOS legacy that you will not find on any online compiler:

  • conio.h offers non-standard and non-portable console functions, like for example the famous kbhit().
  • graphics.h is a vendor specific header for a library that is no longer supported since 1997.

In addition, online compilers provide a command line interface. They are not suitable for graphic development.

Christophe
  • 68,716
  • 7
  • 72
  • 138