while ( a >> b) ?

I am debugging a friend's code and don't understand the following statement:
1
2
while( (istringstream) ss >> (int) numOfElems )
      std::cout<< "..numOfElem = " << numOfElems << std::endl;

The casts were placed there for reference.

What I don't understand is: what does that while() statement mean? When will [code
ss >> numofElems[/code] be false? Does that mean "should the first thing in ss not be an integer, try again until it is?" After all, operator>> returns *this, which will always point to a memory slot, no? Or does *this==NULL once the istringstream runs off its associated string?
It returns an istringstream, yes. Putting that into a boolean check will return, basically, istringstream.good(). So will keep reading into numOfElems until you hit end of file or an error occurs, since good() will return false at that point.
Btw, you probably shouldn't include the types like that, since as it is it looks like you are trying to cast numOfElems to a int, which makes no sense in this situation. Just put them in a separate code (or preferably, put it in a comment block).
Topic archived. No new replies allowed.