Topic: EOFs in unformmated stream output
Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/11/10 Raw View
>>>>> "OG" == Olivier GALIBERT <galibert@mines.u-nancy.fr> writes:
OG> "Steve Downey" <steve.downey@servicing.com> writes:
>> Given:
>> #include <iostream>
>> #include <fstream>
>>
>> int main()
>> {
>> fstream f("test.out",ios::out |ios::binary |ios::trunc);
>> int eof = char_traits<char>::eof();
OG> ios_traits<char>::int_type eof = ios_traits<char>::eof();
[...]
I believe the DWP no longer specifies an ios_traits template
(they were consolidated into the char_traits template at the
Santa Cruz meeting).
Daveed
---
[ comp.std.c++ is moderated. 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 ]
Author: "Steve Downey" <steve.downey@servicing.com>
Date: 1996/11/07 Raw View
Given:
#include <iostream>
#include <fstream>
int main()
{
fstream f("test.out",ios::out |ios::binary |ios::trunc);
int eof = char_traits<char>::eof();
char c = 'X';
f.write((const char*) &eof, sizeof eof );
f.write(&c, sizeof c );
return 0;
}
According to the standard what should be written out to the file? The
implementation I'm using skips over eof's in unformatted stream output, but
that doesn't seem to me to be the right thing to do.
---
[ comp.std.c++ is moderated. 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 ]
Author: galibert@mines.u-nancy.fr (Olivier GALIBERT)
Date: 1996/11/08 Raw View
In article <01bbccc5$c03e90d0$3c8f06ce@io>, "Steve Downey" <steve.downey@servicing.com> writes:
> Given:
> #include <iostream>
> #include <fstream>
>
> int main()
> {
> fstream f("test.out",ios::out |ios::binary |ios::trunc);
> int eof = char_traits<char>::eof();
ios_traits<char>::int_type eof = ios_traits<char>::eof();
> char c = 'X';
> f.write((const char*) &eof, sizeof eof );
> f.write(&c, sizeof c );
> return 0;
> }
>
> According to the standard what should be written out to the file? The
> implementation I'm using skips over eof's in unformatted stream output, but
> that doesn't seem to me to be the right thing to do.
Since ios_traits<char>::int_type is an integer type it must write an
unspecified amount of bytes containing an unspecified value in an
unspecified order. Then it should write a char. In a typical implementation
the result will be a 5-byte file containing 0xff 0xff 0xff 0xff 0x58 (i.e
4-bytes int -1 then ascii char 'X'). I don't see how the f.write can't even
recognize that eof is an int_type and contains eof.
Sarayan
[ comp.std.c++ is moderated. 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 ]
Author: ken@digitas.org (Ken Shan)
Date: 1996/11/09 Raw View
Olivier GALIBERT (galibert@mines.u-nancy.fr) wrote:
> Since ios_traits<char>::int_type is an integer type it must write an
> unspecified amount of bytes containing an unspecified value in an
> unspecified order. Then it should write a char. In a typical implementation
> the result will be a 5-byte file containing 0xff 0xff 0xff 0xff 0x58 (i.e
> 4-bytes int -1 then ascii char 'X'). I don't see how the f.write can't even
^^^^^
> recognize that eof is an int_type and contains eof.
I hope the above "can't" was intended to be "can"... then I agree (:
--
blue | Ken; Shan, Chung-chieh; Sian7, Tiong1-kiat8; ccshan@fas.harvard.edu.
() | Your code today becomes the mind tomorrow: Your plan its means,
/\ | your dream its ends, your ideal its elegance. Hack on.
---
[ comp.std.c++ is moderated. 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 ]