Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: ios_base::a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 9819 of 10094
Post > Topic >>

Re: ios_base::app Standard behavior

by Alberto Ganesh Barbati <AlbertoBarbati@[EMAIL PROTECTED] > Jul 23, 2008 at 07:19 PM

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! ]
 




 6 Posts in Topic:
ios_base::app Standard behavior
francois.cppdevs@[EMAIL P  2008-07-22 21:02:14 
Re: ios_base::app Standard behavior
Jack Klein <jackklein@  2008-07-23 02:32:00 
Re: ios_base::app Standard behavior
Alberto Ganesh Barbati &l  2008-07-23 19:19:20 
Re: ios_base::app Standard behavior
Alberto Ganesh Barbati &l  2008-07-24 05:12:25 
Re: ios_base::app Standard behavior
Jack Klein <jackklein@  2008-07-25 03:28:16 
Re: ios_base::app Standard behavior
francois.cppdevs@[EMAIL P  2008-07-29 10:58:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:28:34 CDT 2008.