Saving Strings to ROOT Files

I am having some issues saving and reading strings from ROOT files.

I am trying to save using the following code which compiles and runs without complaint.

string data;

//some code here


However, when I try to read using the following, I get a seg fault


string data;

//some code here to get entry, etc




a std::string is not a char*, which is what you “promise” to pass by defining the branch as “/C”. Simply do char* data = new char[1024] when filling, and when reading define it as char* data = 0; Or, better yet, create the branch with a TString, using the object pointer overload of TTree::Branch(), i.e. TString* pdata = &data; PostSel->Branch(“data”, &p_data).

Cheers, Axel.