Plot name

Hi all,
I have a txt file whose first line is:

I would like to read the "O2008bws.gif"string from my root script, writing it in the “plotname” string and save the plot produced by the root script with this name. I do in the following way, but it gives me errors:

#include "TString.h" ... string name; ifstream infile("bws_profile.txt"); infile>>name; SaveAs->(plotname);

Can anybody tell me where I’m wrong?

many thanks

what does it mean?


You probably meantsomehistogram->SaveAs(name)You also need to add some code to skip/remove the first characters (#). (name.erase(0,1); might work.)


thanks, but it still doesn’t work :frowning:

With SaveAs->(plotname);
I was meaning:

canvas->SaveAs(name); (sorry).

If [quote]name[/quote] is a string, I was expecting [quote]SaveAs(name)[/quote] working, while it tells to me it cannot call “TCanvas::SaveAs(name)” in current scope…

How can I give the name of the plot image without writing it explicitely within quotes?

If I add name.erase(0,1) as I would like to do, it tells me “can’t call name.erase(0,1)”.

Is string name; the right way to define “name” as a string object?


SaveAs( name.c_str() )

Anar is correct. SaveAs takes as an argument a ‘const char*’ and std::string as no automatic converter to ‘const char*’, hence you must use the explicit call (canvas->SaveAs(name.c_str())