francois.cppdevs@[EMAIL PROTECTED]
ha scritto:
> Hello
>
> According C++ Standard 27.8.1.3 Table 92 when a file stream is
> opened with ios_base::out | ios_base::app it should behave like fopen
> with "a" open mode.But I discovered that fopen is platform dependent,
> under my Linux file pointer is set at end of file after it has been
> open on Windows it stays at beginning. So what should a C++ Standard
> implementation do:
>
> 1. Follow platform dependent fopen behavior ?
According to the C standard, the effect of the "a" flag is "all write to
the file are forced to the current end-of-file, regardless of
intervening calls to the fseek function." In particular, it does not
require nor imply that the initial position of the stream should be set
at the end of file, so you shouldn't rely on that behaviour.
> 2. Always stay at the beginning of file once the file is open?
Moving to the beginning of the file is pointless, as any write operation
will move you at the end-of-file anyway.
> 3. Always move to the end of file once the file is open (like ate) ?
Using ios::ate is a good option, if you need consistent behaviour.
However, in the minimal open-append-close scenario, the position of the
file pointer is irrelevant (all writes occurs at eof anyway) so why care?
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|