I guess that by directly you are referring to specifying a string literal as in FindObject("name"). Both, c_str() member function of std::string and TString::Data() should return a C string (NUL terminated), which shouldn’t have any difference w.r.t. a string literal.
Therefore, as @Wile_E_Coyote suggested, make sure that the original std::string or TString contains what you expect.
So, the problem may be a bit different. I tried to get the histogram with Get instead of FindObject. It worked for case 1 and 2, but not for case 3 which is the one that i want to use. It looks like coming from the addition of 2 strings. This is the relevant part of the code
Sys : Systematics/hhttbbVBFl1cvv0p5cv1_SysTAUS_TRUEHADTAU_EFF_RNNID_HIGHPT__1down
hhttbbVBFl1cvv0p5cv1_SysTAUS_TRUEHADTAU_EFF_RNNID_HIGHPT__1down
hhttbbVBFl1cvv0p5cv1_SysTAUS_TRUEHADTAU_EFF_RNNID_HIGHPT__1down
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_8:1:
/afs/cern.ch/work/p/pbellos/HH_WS/WSMaker_HH_bbtautau/inputs/Rew.cpp:63:11: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
cout<< H3->GetName()<<endl;
I also checked for aditional space character at the end of the “str” string in the txt file. Any other suggestion?
@panagiotis_bellos Also, for future reference (and similar issues), if a string is coming from a text file, you might also need to ensure that the file was not written using a multi-byte encoding.
That might be especially confusing, as your terminal emulator might still render the “expected” character sequence, while the null-terminated C string that you are passing contains extra bytes.