This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 7 Mar 2003 15:58:07 -0800
- Subject: Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- References: <07D05A69A3D0C14FAEA60C3ACE8E5564028F5533@nike.hir.is> <20030307195055.GD15175@tofu.dreamhost.com> <3E690E60.8040000@unitus.it>
On Fri, Mar 07, 2003 at 10:25:52PM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
>
> >>int_type c;
> >>while ((c = sbin->sbumpc()) != traits_type::eof() &&
> >> (sbout->sputc(c) != traits_type::eof())
> >> {}
>
> ... in the application I want to count separately the number of
> succesful reads (__charsread) and writes (__xtrct) like this:
>
> __xtrct = __charsread = 0;
> int_type __c = __sbin->sgetc();
> while (!_Traits::eq_int_type(__c, _Traits::eof()))
> {
> ++__charsread;
> if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
> _Traits::eof()))
> break;
> ++__xtrct;
> ++__ret;
> __c = __sbin->snextc();
> }
>
> and can't see a straightforward way to use your suggestion. Can you?
Here's my best.
__xtrct = __charsread = 0;
while (true)
{
int_type __c = __sbin->sbumpc();
if (_Traits::eq_int_type(__c ), _Traits_type::eof())
break;
++__charsread;
__c = __sbout->sputc(__c);
if (_Traits::eq_int_type(__c, _Traits_type::eof()))
break;
++xtrct;
++ret;
}
Not so elegant, perhaps, but clear.
Nathan Myers
ncm-nospam at cantrip dot org