Article View: comp.std.c++
Article #3608Re: Streams and eof()
From: Steve Clamage
Date: Thu, 07 Mar 1996 13:40
Date: Thu, 07 Mar 1996 13:40
34 lines
2040 bytes
2040 bytes
In article 6o7@fu-berlin.de, axl@zedat.fu-berlin.de (Axel Thimm) writes:
>kanze@gabi-soft.fr (J. Kanze) wrote:
>>You might want to try the function `peek'. I tend to use this function
>>a lot. Basically, this forces a look-ahead, which will set the eof if
>>there is nothing more there.
>But I think that you can use this only with text streams, not with
>binary streams (You would not be able to tell a eof-char from an
>ordinary binary char).
No, it must work. EOF is required to have a value different from every
character value. The character-reading functions that can return either
a character or EOF return a type that that can represent the EOF value
as distinct from any character value.
In a traditional implementation, EOF has the int value -1, and characters
have 8-bit values. The peek function returns the character value promoted
to type int without sign extension, as if by the cast sequence
(int)(unsigned char)the_value
Such a value cannot compare equal to the int value -1.
The situation is more complicated for wide characters, but the principle
remains.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Technical Details
Message-ID:
<4hkean$mrc@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<4hgap6$6o7@fu-berlin.de>Show Full Headers
Complete Article Headers
From: clamage@Eng.Sun.COM (Steve Clamage) Message-ID: <4hkean$mrc@engnews1.Eng.Sun.COM> X-Original-Date: 6 Mar 1996 16:25:59 GMT Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 07 Mar 96 13:40:54 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Streams and eof() Organization: Sun Microsystems Inc. References: <4hgap6$6o7@fu-berlin.de> Reply-To: clamage@Eng.Sun.COM X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMT7ncuEDnX0m9pzZAQHhvQF/XVgxMOoiU7qCdMkaSZeYb5JlvoUBLtrx xbrwrBjnZgsGHxwjaomy7MzADE9Bd2zM =+p2N