#include "graphics.h"

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>
#include<iostream>
using namespace std; 
int main(void)

{

   /* request autodetection */

   int gdriver = DETECT, gmode, errorcode;

   int midx, midy;



   /* initialize graphics and local variables */

   initgraph(&gdriver, &gmode, "");



   /* read result of initialization */

   errorcode = graphresult();

   if (errorcode != grOk) {    /* an error occurred */

      printf("Graphics error: %s\n", grapherrormsg(errorcode));



      printf("Press any key to halt:");

      getch();

      exit(1);                 /* terminate with an error code */

   }



   midx = getmaxx() / 2;

   midy = getmaxy() / 2;

   setcolor(getmaxcolor());



   /* for centering screen messages */

   settextjustify(CENTER_TEXT, CENTER_TEXT);



   /* output a message to the screen */

   outtextxy(midx, midy, "Press any key to clear the screen:");



   getch();   /* wait for a key */

   cleardevice();   /* clear the screen */



   /* output another message */

   outtextxy(midx, midy, "Press any key to quit:");

   /* clean up */

   getch();

   closegraph();

   return 0;
}

i try it but it gives error lbgi not found but i also put the liker code in parameter list

Do you have graphics.h on your system? From what I remember graphics.h is a very old deprecated header from the good old DOS days. I wouldn't think it would be in GCC 4.x.

Headers like "conio.h" and "graphics.h" are extremely old and obsolete headers from another era. I think that they are too old even for an ancient IDE like Dev-C++ 4.9.9.2. The direct graphics (GDI) that this library uses has been deprecated for quite some time. I think there is probably still a way to use them through backward-compatible libraries provided by Windows, but I'm not sure what they are or how to link to them (or if you even can without special measures taken).

People simply don't use this stuff anymore, and haven't for at least a decade or two.

Also, using <stdlib.h> and <stdio.h> is not standard C++, the standard equivalent of those libraries are <cstdlib> and <cstdio>. The code that you have there is what we call "pre-standard C++", which dates back to the early 90s, before the first standard for C++ (in 1998). The biggest problem really is that you are basically doing software archeology (looking at legacy code from an ancient and forgotten era of programming civilization). And for such a trivial piece of code, I don't see the point in trying to revive it.

Plenty of people still program with ancient, pre-standard compilers, particularly in places like India.

Also, there does exist the WinBGIm port for MinGW, so old BGI code certainly can and does compile with modern GCC.

Alas, I am currently reinstalling my compiler (I managed to hose it with an 'automatic update' process -- never trust those), so I cannot compile and test your code right now. That said, I don't see anything obviously wrong with it.

What exactly is the error you are getting when you run it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.