This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]