RE: TString bug (or feature)?

From: Arthur E. Snyder <snyder_at_slac.stanford.edu>
Date: Wed, 4 Apr 2007 10:12:18 -0700 (PDT)


A simple example. Routines are attached. I compile and link it to my private library libAES.so.

Running testRead I get:

root [1] testRead()
count:0 temp:x
count:1 temp:y
na:2
0:x
1:y
root [2]

It skips z because eof is set.

Switching to the std::string version for reading, I get:

root [1] testRead()

count:0 temp:x
count:1 temp:y
count:2 temp:z

na:3
0:x
1:y
2:z

root [2]

So that works fine.

It may have something do with istringstream. If I read the ifstream directly (using TString version of read) it works ok. Only when I read a card 1st do I have the problem.

-Art S

A.E. Snyder, Group EC                        \!c*p?/
SLAC Mail Stop #95                          ((.   .))
Box 4349                                        |
Stanford, Ca, USA, 94309                      '\|/`
e-mail:snyder_at_slac.stanford.edu                 o
phone:650-926-2701                              _
http://www.slac.stanford.edu/~snyder          BaBar
FAX:650-926-2657                          Collaboration



On Wed, 4 Apr 2007, Philippe Canal wrote:

> Hi Arthur,
>
> I can not reproduce the problem (or do not understand your description :) ).
>
> Can you send me a complete running example (and the output as you see it)
> as well as the version of ROOT where it fails for you).
>
> Cheers,
> Philippe.
>
> -----Original Message-----
> From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch]
> On Behalf Of Arthur E. Snyder
> Sent: Monday, April 02, 2007 4:43 PM
> To: Rene Brun
> Cc: 'roottalk (Mailing list discussing all aspects of the ROOT system)'
> Subject: [ROOT] TString bug (or feature)?
>
> Hi Rene et al.,
>
> I find that when I try to read the blank separated charachters in a line
> into TString from an istringstream it has a strange behavior. If the last
> character is followed directly by a line-feed it gets skipped. Apparently
> eof or something is set by reading it and the loop ends w.o. giving you a
> chance at the characters just read. The result is you lose the last
> character string. If I use std::string instead, it works as I expect it
> too.
>
> The code is as follows:
>
> #include "readCard.hh"
> #include <TString.h>
> #include <iostream>
> #include <vector>
> #include <string>
>
> using std::istream;
> using std::endl;
> using std::cout;
>
> //read strings till "eol" marker or natural end; if nread!=0 read nread
> string (no marker)
> Int_t readCard(istream& card,std::vector<TString>& list,Int_t nread) {
> Int_t count=0;
>
> TString temp;
> // std::string temp;
> while(card >> temp) {
>
> cout << "count:" << count << " temp:" << temp << endl;
>
> if(nread==0 && temp=="eol") break;
> if(nread==0 && temp=="*eol") break;
> if(nread==0 && temp=="!eol") break;
> count++;
>
> list.push_back(temp);
> if(count==nread) break;
>
> } // loop
>
> return count;
> }
>
> -Art S.
>
>
>

Received on Wed Apr 04 2007 - 19:12:31 CEST

This archive was generated by hypermail 2.2.0 : Thu Apr 05 2007 - 17:50:01 CEST