Iostream, some questions

I saw people doing things like ....

 istringstream ibuf;

 if (ibuf >>  zork >> iA >> Comma >> iB)

Now I assume that the value depends on what → iB provides, but exactly what is it and what does it mean? Does this really mean that all ietms have been extracted?

Also, after an expression like

 ibuf >>  zork >> iA >> Comma >> iB;

is there any way to find out how many characters and elements are extracted?

+5
source share
3 answers

This works because of two properties of istream objects:

  • istreams are returned after each retrieval (operator >>) to allow a chain of multiple selections ( a >> b >> c)
  • istreams return their status (as if called .good()) when they were translated / converted to bool, overloadingbool operator !()

, , :

if ( ((((ibuf >> zork) >> ia) >> Comma) >> ib).good() ) {

}

, if (ibuf), if ((bool)ibuf), ibuf.good().

, , , , gcount. , , get getline, .

+3

ibuf , . operator >>() istringstream. .

gcount, . , , . read.

Edit:

(ibuf >>  zork >> iA >> Comma >> iB)

:

((((ibuf.operator >>(zork)).operator >>(iA)).operator >>(Comma)).operator >>(iB))

( ).

+1
if (ibuf >>  zork >> iA >> Comma >> iB)

:

ibuf >> zork;
ibuf >> iA;
ibuf >> Comma;
ibuf >> iB;
if (ibuf) ...

" , ?"

- "gcount": http://www.cplusplus.com/reference/iostream/istream/gcount/

0
source

All Articles