C ++图形初始化图形错误(语法或文件缺失缺陷?) [英] C++ graphics initgraph error (syntax or missing-file flaw?)

查看:143
本文介绍了C ++图形初始化图形错误(语法或文件缺失缺陷?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[已解决]

我在Win10上使用CodeBlocks(C ++).我试图创建一个简单的图形程序-下载了一个特定的图形程序包(graphics.h和与BGI有关的其他两个文件-我在设置中添加了lib等).我尝试了此程序,但标出的行似乎有问题.我以正确的方式(至少是部分方式)从Pascal(作为我的老师-是的,这是关于大学的-仅向我们展示Pascal程序)移植过来的.问题肯定出在指针上(解决后不是!请检查我的回答).如有需要,我会提供更多详细信息.

I'm using CodeBlocks (C++) on Win10. I tried to create a simple graphic program - I downloaded a certain graphics package (graphics.h and other two files related to BGI - I added the lib in settings etc.). I tried this program but there seems to be a problem at the line marked. I ported this from Pascal (as my teacher -yes, it's about college-, only shows us Pascal programs) in a correct manner I suppose, or at least partially. The problem is certainly with the pointers (EDIT AFTER SOLVING: it wasn't!, check my answer). I'll give more details if needed.

问题:我在哪里犯过错误以及如何纠正错误(写什么,添加什么,删除什么),以便可以正常工作?如果代码没有错误,但是我需要一些文件供图形在我的编译器上使用,这些文件是文件,在哪里获取和放在哪里?

错误(不完全是,现在是警告"):

ERROR (not quite, now's a "warning"):

deprecated conversion from string constant to 'char*' [-Wwrite-strings]

(请参见下面的代码)

请阅读:非常感谢您提供程序的固定版本.引用是无用的,所以除非您真的想要帮助我(谢谢!),否则请离开此页面.我唯一相关的能力是比较一个程序的两个版本,这些版本旨在执行相同的操作,但一个版本有错误(或多个).

Please read: I would BE VERY GRATEFUL for a fixed version of my program. Refferences are USELESS, so unless you REALLY want to help me (thank you!), leave this page. My only related capacity is to compare two versions of a program that are intended to do the same thing but one has a mistake (or more).

代码(已更新!):

#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;
int main(){
int gr,xmax,ymax,r;
int gm,gd;
gd=DETECT;
gm=0;
initgraph(&gd, gm, "C:\\TC\\BGI"); /*edit(solved): followed the tutorial linked in my answer; not a directory in my PC.*/
gr=graphresult();
if(gr!=grOk) cout<<"Error!";
    else    {xmax=getmaxx();
            ymax=getmaxy();
            cout<<"Resol.: "<<xmax+1<<"x"<<ymax+1;}
setcolor(7);rectangle(0,0,xmax,ymax);setcolor(5);line(0,0,xmax,ymax);line(0,ymax,xmax,0);setcolor(3);
for(r=(ymax+1)/2;r>=0;r--) circle((xmax+1)/2,(ymax+1)/2,r);
getch();
closegraph();
return 0;
}

graphics.h来源和指南: http://www.codewithc.com/how-to-include-graphics-h-in-codeblocks/

graphics.h source and guide: http://www.codewithc.com/how-to-include-graphics-h-in-codeblocks/

推荐答案

已解决! 将CB降级(我认为v16到v13,不确定是否有必要)并替换了一些文件. 我遵循了本教程: https://m.youtube.com/watch?v=FxCdMM9H66I 它与问题中的链接完全相同,但是前一个链接中的那些文件(graphics.h,winbgim.h,libbgi.a)(一个或多个)可能存在错误,或者存在一些明显的错误,或者不兼容等),而我在此答案中提供的vid制造商给出的文件已得到纠正.我不(真的想)知道. 现在,警告仍然出现,但是程序运行正常! 我将r = 0替换为r> = 0,这是一个小错误. (如果可以的话,我会更新问题)

Solved! Downgraded CB (v16 to v13 I think, not sure if it was necessary) and replaced some files. I followed this tutorial: https://m.youtube.com/watch?v=FxCdMM9H66I It was quite the same as the link in the question but probably (one or more of) those files (graphics.h, winbgim.h, libbgi.a) from the previous link were bugged, had some unobvious errors or so, or were incompatible etcetera), while the files given by the maker of the vid I provided in this answer were corrected. I don't (really want to) know. Now, the warning still appears, BUT the program runs perfectly! I replaced r=0 with r>=0 , this was a minor mistake. (I'll update the question if I still can)

感谢您的帮助! (我不会说没事") :)

Thanks for... your help! (Can't say "nothing", I'd be mean) :)

一些显示圆的更清洁"版本(只是意识到问题中的变体不显示实心圆):

Some "cleaner" version that shows the circle (just realised the variant in the question doesn't display the filled circle):

#include<iostream>
#include<graphics.h>
#include<dos.h>
using namespace std;
main(){
int gm,gd,gr,xmax,ymax,r;
gd=DETECT;
gm=0;
initgraph(&gd,&gm,"C:\\TC\\BGI");
gr=graphresult();
if(gr!=grOk) cout<<"Error!";
    else    {xmax=getmaxx();
            ymax=getmaxy();
            cout<<"Res.: "<<xmax+1<<"x"<<ymax+1;}
setcolor(7);
rectangle(0,0,xmax,ymax);
setcolor(5);
line(0,0,xmax,ymax);
line(0,ymax,xmax,0);
setcolor(3);
for(r=(ymax+1)/2;r>=0;r--) circle((xmax+1)/2,(ymax+1)/2,r);
getch();
closegraph();
}

无需降级确认! :D

Downgrading not necessary CONFIRMED! :D

这篇关于C ++图形初始化图形错误(语法或文件缺失缺陷?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆