How do I graph data in c++?

Viewed 132

I am trying to make a graph using graphics.h in c++. I was following a tutorial on youtube. It seems that either due to the age of the video (perhaps the syntax has changed slightly?) or a problem on my end; I cannot even get a separate window for my graph to open. I am in completely uncharted waters for me as the limit of my coding knowledge is what you would expect to learn from a first-semester coding class. I am using DEV C++ and am compiling using "TDM-GCC 4.9.2 32-bit Release" (because the 64 bit release gives me an error in "Makefile.win" that scares me) and my program exits with a return value of 3221225477. What am i doing wrong?

#include"graphics.h"
#include<math.h>
#include<conio.h>
#include<iostream>
using namespace std;

int main() {
    
    initwindow(800,600);
    int x,y;
    line(0,300,getmaxx(),300);
    line(400,0,400,getmaxy());
    float pi=3.14159;
    
    for(int i=-360;i<=360;i++){
        
        x=(int)400+i;
        y=(int)300-sin(i*pi/100)*25;
        putpixel(x,y,WHITE);
    
    }
    
    getch();
    closegraph();
    
    return 0;
}
1 Answers

According to your issue and exit-code, the return value in hex is 0xC0000005 or STATUS_ACCESS_VIOLATION. But most developers didn't even bother to learn out-dated legacy API and I can not help you to find the exact line (use debugger, it shows you the exact line, still not the reason).

But to answer your question in the title, well, according to what free framework one uses (Qt or XWidget), the method differs, for Qt (which I would recommend) simply override paint-event and use QPainter renderer to show your QPath data.

Don't reinvent the wheel (or render-system in this case), your course and/or book may soon introduce you to one of the mentioned frameworks.

Related