我什么都试过了,连这个简单的图代码都启动不了。我已经在所有正确的文件夹中安装了 graphics.h、winbgim.h 和 libbgi.a。 (包括和库)。链接器也是 -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
我正在使用 CodeBlocks 16.01。我也在 Dev-C++ 中尝试过,但没有成功。
首先我得到错误:
C:\Program Files (x86)\CodeBlocks\MinGW\include\graphics.h|302|error: redefinition of 'int right'
但是我通过更改graphics.h文件解决了,int right
需要替换成int top
。
还有1个警告-
C:\Users\Davor\Desktop\New Project\drugi\main.cpp||In function 'int main()':| C:\Users\Davor\Desktop\New Project\drugi\main.cpp|15|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]| ||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
在那之后,当我按下“Build and run”时,我得到了
" *.exe has stopped working. " In the background I first get -
Process returned 255 (0xFF) execution time : 91.666 s Press any key to continue.
但每隔一段时间我都会 -
Process returned -1073741819 (0xC0000005) execution time : 26.494 s Press any key to continue.
#include <iostream>
#include <cstdlib>
#include <graphics.h>
using namespace std;
int main() {
int gdriver = 9;
int gmode = 2;
int x;
initgraph(&gdriver, &gmode, "");
setbkcolor (WHITE);
setcolor (BLACK);
cleardevice();
for (x = 260; x < 364; x = x + 5)
{
circle(x,240,60);
}
getch();
closegraph();
return 0;
}
最佳答案
不看里面<graphics.h>
, 看起来 initgraph()
被声明为采用(非常量)char* 作为第三个参数 - 暗示它是一个输出 参数,指向一个可写的 char 数组 initgraph()
将写入。
除了生成您引用的警告外,还传递字符串常量 ""
因为参数会导致未定义的行为,其中崩溃就是一个很好的例子。
虽然我上面的评论是有效的,但在查看文档后我会推测该参数不是输出参数,并且缺少 const
只是糟糕的 API 实现——显然没有任何方法来确定初始化是否真的成功......
关于c++ - 无法通过 C++ 警告 : (& crash after) deprecated conversion from string constant to ‘char*’ [-Wwrite-strings],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37047981/