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]

Re: Strange stream behaviour


Nathan Myers wrote:
> 
> On Sat, Oct 06, 2001 at 06:35:57PM +0400, Roman Belenov wrote:
> > I've found that simple copy program
> >   #include <iostream>
> >   int main()
> >   { int ch; while( (ch = std::cin.get()) != EOF ) std::cout.put(ch); }
> >
> > duplicates pieces from input, first occurence being about
> > position 3000 in the input stream.
> 
> There is no reason to expect the program to work.  In particular, the
> function cin.get() can never return EOF under any circumstances.  EOF
> is an int constant, where cin.get() can only return character values.
> The loop termination condition for such a program must check the
> stream state, not the result of cin.get().

I must be missing something but I don't see anything wrong with the
program. The function is declared to return int_type and 27.6.1.3,
p4 clearly says that the function returns the extracter character
if one is available, otherwise traits_type::eof(), which in this
case is the same as EOF.

Regards
Martin


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