'Graphics.h Not Working in VS Code version 1.15.1

Context Language : C++ , Editor : Microsoft Visual Studio Code Version 1.15.1

Problem I am using Microsoft Visual Studio Code Version 1.15.1 for Compiling my C++ Programs. I want to use Graphics.h to use Graphics in my C++ Programs. That's why I downloaded the Three files Graphics.h ,winbgim.h and libbgi.a and Put them into the Right Places.I also Downloaded an BGI folder from https://www.cs.colorado.edu/~main/bgi/visual/BGI2010.zip and Put it into the Right Place. But When I am Compiling My Program then it Showing Some error.

My C++ Program

    #include<iostream>
    #include<math.h>
    #include<graphics.h>
    using namespace std;
    int main(){
        int x,y;
        int gd = DETECT ,gm;
        initgraph(&gd,&gm,"C:\\MinGW\bgi");
        cout<<"Enter the Value of X Co-ordinate : ";
        cin>>x;
        cout<<"Enter the Value of Y Co-ordinate : ";
        cin>>y;
        putpixel(x,y,WHITE);
        closegraph();
    }

Error of my Program

computerGraphics1.cpp: In function 'int main()':
computerGraphics1.cpp:8:25: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     initgraph(&gd,&gm,"C:\\MinGW\bgi");
                         ^
C:\Users\TUSK\AppData\Local\Temp\ccEbDqZq.o: In function `main':
C:\Users\TUSK\Desktop\Practise\C++ Projects/computerGraphics1.cpp:8: undefined reference to `initgraph'
C:\Users\TUSK\Desktop\Practise\C++ Projects/computerGraphics1.cpp:13: undefined reference to `putpixel'
C:\Users\TUSK\Desktop\Practise\C++ Projects/computerGraphics1.cpp:14: undefined reference to `closegraph'
collect2.exe: error: ld returned 1 exit status

So Guys who ever Finds its Solution Please Answer it



Solution 1:[1]

Detailed setup if you want to use graphics.h in VC Code.

This worked for me...

char driverPath[] = "C:\\MinGW\\lib\\libbgi.a"; //static file
initgraph(&gd, &gm, driverpath);

Solution 2:[2]

You can "fix" the error with a const_cast, but beware, if ever you do try to modify the string contents you can expect a crash.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adrian Mole
Solution 2 Paul Floyd