Store already plotted TGraphs in a root file

Hello,

I have a question regarding TGraphs and storing them in the root file. Anyway, I have created two TGraphs separately, and I want to create a new root file and store the graphs there. I have started with a code

TFile *f = TFile::Open(“Selection.root”, “RECREATE");

I don’t know what to do after that. I have tried several examples from the forum and tutorials, but nothing seems to work. That’s because I want to store already plotted graphs. I appreciate the help.

f->cd(); graph1->Write("MyGraph1"); graph2->Write("MyGraph2"); delete f;

Hi Coyote,
thank you so much for your answer. I have tried this but I’m getting this error:
use of undeclared identifier ‘graph1’
use of undeclared identifier ‘graph2’

These should be pointers to your real graphs.

Thank you again for your quick answer. I tried to put the TGraphs’ titles and also the names of the cpp files as pointers, but root didn’t find them. Am I making a mistake?

I managed to solve it. I’ve made a simple mistake. Thanks again!