RE: [ROOT] print numbers in scatter plots.

From: David Bailey (Antares Post Graduate) (d.bailey2@physics.ox.ac.uk)
Date: Wed Jul 04 2001 - 19:39:53 MEST


Hi all,
> 
> There are better and simple procedures to encode an integer 
> in a string.
> A conservative and general procedure is the following: 
> Instead of the lines:
> 
>       std::ostringstream buffer;
>       buffer << index;
>       string s = buffer.str();
>       char *c = new char[s.length()+1];
>       strcpy(c, s.c_str());
>       tex = new TLatex(tr.x(),tr.y(),c);
> 
> do:
>       char c[4];
>       sprintf(c,"%d",index);
>       tex = new TLatex(tr.x(),tr.y(),c);
> 
Alternatively, to still use the C++ stringstream classes, the following more
concise version of the above is possible:

std::ostringstream buffer;
buffer << index << ends;
tex = new TLatex(tr.x(),tr.y(),buffer.str());

The "ends" (end stream) is missing from the above - like missing the \0 from
the end of a c-style string. I hope this helps,

  Cheers, Dave Bailey

------------------------------------------\
-   David Bailey : Antares post-Graduate  /
-   Nuclear and Astrophysics Laboratory  /
-   Keble Road, Oxford OX1 3RH   /------/
-   (01865) 273442   /----------/ d.bailey2@physics.ox.ac.uk
--------------------/ http://www-pnp.physics.ox.ac.uk/~daveb 



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:51 MET