I am looking for an easy way to convert numbers (Int_t, Double_t) into strings.
What i want to do is to create dynamical columns in my ntuple and fill them. Something that should look like:
string nameA=“ColumnNameA”, nameB=“ColumnNameB”;
Int_t intA, intB; //or Double_t
loop over x
intA[x] = 123;
intA --> to string --> stringA
Maybe somebody knows a nifty way to do something like that.
Cheers & Thanks,
In standard C/C++ one would use sprintf. In addition ROOT provides also the “Form” function. It returns a string.
s1 = Form("i = %d",i);
s2 = Form("%g is a float",r);
“Form” seems to be excactly what I was looking for.
Another way to do the conversion is by using string streams (from STL).You can use them as regular string streams and then recover the string:
int number = 23;
string tip = "show";
mysstream << tip << " number " << number;
string line = mysstream.str();
cout << line << endl;
will output: “show number 23”