cin/streambuf-problem
R. Sinoradzki
sinoradz@student.uni-kl.de
Sat May 19 12:15:00 GMT 2001
Thanks for your reply.
Perhaps I understand something wrong. But the reason I wonder is that
this method is from Stroustrup, 'The C++ Programming Language' 3rd Edition.
This is what ISO-C++ 98 says.
(quote)
27.5.2.2.3 Get area [lib.streambuf.pub.get]
streamsize in_avail();
Returns: If a read position is available, returns egptr() - gptr().
....
char_type* gptr() const;
Returns: The next pointer for the input sequence.
....
char_type* egptr() const;
Returns: The end pointer for the input sequence.
(end of quote)
I followed the program with my debugger.
'egptr() - gptr()' is returned but the result is 1.
In my opinion it should be the number of characters that are left in the
streambuf.
I perhaps try to compile a full debug-version and watch out, what really
happens.
Regards,
Ralf
Carlo Wood wrote:
>
> On Fri, May 18, 2001 at 11:53:43PM +0200, R. Sinoradzki wrote:
> > I have this little program. It does not behave as
> > expected with gcc-3.0 and it's stdlib.
> > If I type for example "hello" the loop runs 5 times,
> > before the next 'cin' because 'cin.rdbuf()->in_avail()'
> > reports only 1.
>
> >From the top my head (I am not at home right now, but telnetted
> into my PC (no GUI)), streambuf::in_avail() doesn't return the
> number of buffered characters, but only the number that can
> be read quickly (the current contiguous ammount in the get area?).
> I even seem to remember that the default implementation is currently
> to always return 1. In other words: I might be wrong but I think you
> shouldn't use in_avail(), it means something else then you (apparently)
> think it means.
>
> --
> Carlo Wood <carlo@alinoe.com>
More information about the Libstdc++
mailing list