Graphics.h在VS代码版本1.15.1中不起作用

时间:2017-08-29 14:18:53

标签: c++

上下文 语言:C ++ ,编辑:Microsoft Visual Studio Code Version 1.15.1

问题 我使用Microsoft Visual Studio Code Version 1.15.1编译我的C ++程序。我想使用Graphics.h在我的C ++程序中使用Graphics。这就是我下载三个文件Graphics.h,winbgim.h和libbgi.a并将它们放入正确位置的原因。我还从https://www.cs.colorado.edu/~main/bgi/visual/BGI2010.zip下载了一个BGI文件夹并将其放入正确的位置。但是当我编译我的程序时,它显示出一些错误。

我的C ++计划

    #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();
    }

我的计划错误

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

所以找到解决方案的人请回答

2 个答案:

答案 0 :(得分:1)

如果您想在 VC Code 中使用 graphics.h 的详细设置。

这对我有用...

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

答案 1 :(得分:0)

你可以修复&#34; const_cast的错误,但要注意,如果您尝试修改字符串内容,可能会导致崩溃。

相关问题