Printing histograms with strings in the title

I apologize if this has been addressed elsewhere, I can’t seem to find anything quite relevant to my question.

I would like to save histograms using this form:

c1->Print(histname.gif);

But I would like to have part of the name contain information that I can change easily, such that I would like to do something like:

c1->Print"histname_type_date.gif" where “type” and “date” are each a string that I can edit once at the top of my macro as needed. Clearly, this is not the right syntax, but if that gives the idea of what I would like to do enough so that someone can point me to the right method, I would really appreciate it.

Thanks!

You can make a string (char*) that contains the parameters, and then use sprintf.

So, it will be something like
char filename[500];
char type[]="blah"
char date[]="today"
sprintf(filename,“histname_%s_%s.gif”,type,date)

Or if you use pyROOT, it’s even easier, just do

type = “blah"
date = “today"
filename = “histname_”+type+”_”+date+".gif"

You can also use Form() which returns a string you can use directly:

c1->Print(Form(“histname_%s_%s.gif”,type,date));

Thanks for the replies! Using couet’s suggestion solves my problem. That will make my life easier writing all my scripts, thanks!