2017-08-29 83 views
-2

语境 语言:C++ ,编辑:微软的Visual Studio代码版本1.15.1在有Graphics.h VS代码版本无法正常工作1.15.1

问题 我使用微软的Visual Studio代码版本1.15.1编译我的C++程序。我想使用Graphics.h在我的C++程序中使用图形。这就是为什么我下载了三个文件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 

那么,谁曾认定其解决方案专家,请采纳率

+1

''标题和库已过时并已过时。并且是针对允许指向非常量字符串的C的。在C++中,所有文字字符串常量就是这样:***常量***。 *警告*告诉你,因为'initgraph'接受一个非常量字符串的指针(如前所述在C中有效,即使文本字符串是只读字符串)。 –

回答

0

可以 “修复”与const_cast的错误,但要小心,如果永远你试图修改字符串内容,你可能会崩溃。

+0

这里更大的问题可能是各种'graphics.h'函数的链接器错误。 – ComicSansMS