Re: some confusion about TString

Fons Rademakers (rdm@pcsalo.cern.ch)
Wed, 10 Mar 1999 10:11:15 +0100 (MET)


Hi Petar,

first of all, switch to the latest root 2.21/07, an important bug
in operator<<(ostream& os, const TString& s) was fixed in 2.21/03
(this causes the crash in your 2.21/02).

Next here an example of how to use TString::ReadToken(istream&)
via operator>>(istream& strm, TString& s) (of course you also can call
ReadToken() directly):

strstream x;
x << "foo bar"
x.str(); // yes, "foo bar" is there
TString s;
x >> s;
s.Data(); // prints "foo"
x >> s;
s.Data(); // prints "bar"

Hope this helps.

Cheers, Fons.

> Hi all,
>
> I'm a little confused about some uses of the TString class. What I
> ultimately want to do is to tokenize a command line. (I'm trying to
> write a layer on top of TMinuit::mnexcm() and avoid creating the
> annoying array of needed to supply arguments.)
>
> The web page for TString claims that there is a member function
> istream& ReadToken(istream& str) that seems perfect for the job. Does
> anybody have an example on how to use it (the whole root web site
> contains only two references to it -- in the class definition).
>
> Also, one would naively expect the following few commands to work:
>
> root [0] #include <iostream.h>
> root [1] TString test = "one two three";
> root [2] cout << test << endl;
>
> *** Break *** segmentation violation
>
> I'd appreciate a hint on what I'm missing here.
>
> I'm using root 2.21/02. Thanks a bunch!
>
> Petar
>
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910