There is no real constraint on how many characters underflow()
makes available. The only real constraint is that a stream which hasn't reached EOF needs to make, at least, one character available. With respect specifically std::filebuf
(or std::basic_filebuf<...>
) the stream may be unbuffered (if setbuf(0, 0)
was called) in which case it would, indeed, make individual characters available. Otherwise, the stream will try to fill its internal buffer and rely on the operating system to have a the underlying operation return a suitable amount of bytes if there are few available, yet.
I'm not sure I quite understand your question: the operation file >> x
will return once x
is completely read which can happen if the stream indicated by file
has reached its end or when a whitespace character is found (and if with "string" you mean char*
, a non-zero value stored in file.width()
is also taken into account). With respect to the underlying stream buffer, clearly x
may require multiple reads to the underlying representation, i.e., it is unpredictable how many calls to underflow()
are made. Given that the file's internal buffer is probably matching the disc's block size, I would expect that at most one call to underflow()
is made for "normal" strings. However, if the file read is a huge and doesn't contain any spaces many calls to underflow()
may be made. Given that the stream needs to find whitespaces it has no way to predict how many characters are needed in the first place.