Getting root to display graphs

Hi! So, I’m new to root, and I’m trying to get root to display a graph using the macro

void graph(){
    gROOT->SetStyle("Plain");
    TF1 f1("f1","sin(x)/x",0.,10.);
    f1.Draw();
}

but every time I run the macro, the canvas shows up empty. I can use the commands at the root prompt and get it to display the graph, but not from a macro. Can anyone help? I’m trying to run Root 6.16 on a windows 10 machine. Thanks!

TF1::DrawCopy

BTW. You should learn about the lifetime of “stack-based” and “heap-based” objects in C++.

Thanks, but I don’t follow your second statement. I’m only using the one TF1, so what’s the problem with using draw?

Your “stack-based” TF1 object is automatically deleted when your “graph” function finishes.

Oh, it already goes out of scope, and the canvas doesn’t hold the image? Okay, thanks!