Seg fault at multiple TH1F declaration

Dear all,

I have some confusion regarding to simple situation. I would like to save 288 hists with their own name in std::vector, so to access it easily later and fill.

for (int i =0; i < 288; i++){
        TH1F* histName = new TH1F(Form("resTime-OM%s", i), Form("resTime-OM%s", i), 500, -100, 100);
        delete histName; histName = nullptr;

But my program crashes at 3rd line when i=1. Can anyone clarify why this is happening?

i is an integer, not a string; the error message should be telling you that.

it should be:

TH1F* histName = new TH1F(Form("resTime-OM%d", i), Form("resTime-OM%d", i), 500, -100, 100);
//-----------------------------------------^-------------------------------------------------------------^ .... "d" not "s"

@dastudillo and @couet thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.