How to get branches for various strings?

Hello all,
Am trying to write a tree with a branch which can have various
strings. It compiles fine but I don’t see the strings written correctly. Could anyone please help me with this?
The code I use is:
int n_names;
std::string names[100];
vectorstd::string getnames;
ntriggers =0;
TFile *f=new TFile(“xx.root”,“RECREATE”);
TTree *myEvent = new TTree(“myEvent”,“a tree with histograms”);
myEvent->Branch(“n_names”,&n_names,“n_names/I”);
myEvent->Branch(“names”,names,“names[n_names]/C”);

…(where I get the vector getnames filled)

n_names = (int)getnames.size();
for ( int i=0; i< n_names;i++)
{
triggernames[i] = getnames[i];
}
myEvent->Fill();
f->WriteTObject(myEvent);

Hi,

As indicated in the documentation (please let us know if you found otherwise), the ‘leaflist’ type ‘/C’ is reserved for the C style string (i.e. a char*) and this techniques does NOT support multiple strings. So you would would need:int n_names; char *names = new char[100]; names[0] = 0; TFile *f=new TFile("xx.root","RECREATE"); TTree *myEvent = new TTree("myEvent","a tree with histograms"); myEvent->Branch("n_names",&n_names,"n_names/I"); myEvent->Branch("names",names,"names[n_names]/C"); ..... .....(where I get the vector getnames filled) ..... n_names = (int)getnames[0].size(); strlcpy(triggernames[0],getnames[0].c_str(),100); myEvent->Fill(); f->Write();Alternatively with newer version of root you can use: vector<std::string> getnames; ntriggers =0; TFile *f=new TFile("xx.root","RECREATE"); TTree *myEvent = new TTree("myEvent","a tree with histograms"); myEvent->Branch("names",&getnames); ..... .....(where I get the vector getnames filled) ..... myEvent->Fill(); f->Write();

Cheers,
Philippe.

Thanks Philippe.
Meanwhile I tried with vector of strings too and it worked.

Thanks & Regards
Sandhya