I did exactly what I’ve written.
But it occured to me that maybe ROOT doesn’t like making an array of strings?
If I replace the std::string with something else (Int_t for example) then it works fine.
The problem is that I need the struct to contain strings. What should I do?
I tried to copy and paste in the CINT shell and it also worked. What version of ROOT/Cint are you using? Are you feeding the interpreter with these exact lines? How?
I’m using ROOT version 5 and I’m giving exactly these lines.
It doesn’t complain when I substitute std::string with Char_t string[40], so for now I’m making it work by successively converting the array of characters into a string when I need it.
What do you mean by “giving”? Cint does not allow function definition in a command-line (neither does Cling, except when in rawInput mode).
It is not a problem for ROOT to load a macro called a.C containing these lines
when I run root test.C the script runs fine and prints me out the info, but if instead of Char_t I use std::string for the definition of “filename” and “experiment” then I get a segmentation violation.
I finally can reproduce the crash: it happens at tear down. It seems to be linked to string destructor which happens via CINT internals. I let Axel comment further about this.
The code is
Hello Alex, the code I wrote in my post (the one with strcpy) is an example of code that I modified in order to work. My initial attempt was to make work the code written by dpiparo, which is the following:
Okay, phew, good - so we are talking about the same code.
In that case I agree with Danilo: please either upgrade ROOT to ROOT 6 which can handle this without problems, or compile your macro by running it as “.x text.C+” (note the ‘+’ at the end). This is a bug in CINT but we will not fix this anymore. Or rather: it is fixed by ROOT 6