Converting numbers into string

Hi,

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[42], intB[42]; //or Double_t

loop over x
{
intA[x] = 123;

intA --> to string --> stringA
_myTuple->column(nameA+stringA+"additionalString",(double) value);

}

Maybe somebody knows a nifty way to do something like that.

Cheers & Thanks,
Thomas

In standard C/C++ one would use sprintf. In addition ROOT provides also the “Form” function. It returns a string.

Example:

s1 = Form("i = %d",i);
s2 = Form("%g is a float",r);
etc ...

Many thanks,

“Form” seems to be excactly what I was looking for.

Cheers,
Thomas

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:
Example:

 #include <sstream>
 ostringstream mysstream; 
 int number = 23;
 string tip = "show";
 mysstream << tip << " number " << number;
 string line = mysstream.str();
 cout << line << endl;

will output: “show number 23”