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;
list.push_back(temp);
if(count==nread) break;
} // loop
return count;
}
-Art S. Received on Mon Apr 02 2007 - 23:43:19 CEST
This archive was generated by hypermail 2.2.0 : Wed Apr 04 2007 - 11:50:02 CEST