Convertin TString to string and vice versa

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.10.06
Platform: Ubuntu 16.04
Compiler: gcc530

TString sample = "/Results/trial2.root";
std::cout << "sample is: " << typeid(sample).name() << '\n';
std::cout << "sample is: " << typeid(sample).name() << '\n'

In the code above,

  1. Why does the type say 7TString not TString? what is 7TString?
  2. After Form function, it still stays as 7TString. How can I convert that into string?

Thank you.


To convert a TString to std::string you have to create a new variable of type std::string and vice versa.

This work with root 6.21.01

TString sample = "/Results/trial2.root";
//convert TString to string
std::string sample_string(sample.Data());
//convert string to TString
TString sample_TString(sample_string)