www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/18/13:20:20

From: "Peter Lewerin" <peter DOT lewerin AT krax DOT pp DOT se>
Newsgroups: comp.os.msdos.djgpp
Subject: fstream open mode interpretation
Date: 18 May 1997 11:46:55 GMT
Organization: -
Lines: 25
Message-ID: <01bc6381$26125d40$LocalHost@peterlew>
NNTP-Posting-Host: dialup156-2-10.swipnet.se
NNTP-Posting-User: s-36170
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm trying to translate stdio file operations to fstream f.o. in an
introductory text for beginning programmers.  The problem is with file open
mode "r+".  According to the draft C++ standard
(<http://www.cygnus.com/misc/wp/draft/lib-iostreams.html#lib.filebuf.members
>), the corresponding flags are ios::in|ios::out; the file should not be
truncated unless ios::trunc is set.

However, DJGPP (2.01, gcc version 2.7.2.1) always truncates the supplied
file, regardless of ios::trunc setting.  (This seems to be standard
behaviour for older C++ compilers; TC++ 3.0 does it too.)

Is there any -simple- workaround for this?

 * I suppose I could open a stdio stream and use the file descriptor as a
parameter to the fstream ctor, but, hey...
 * ios::app is no use, either; I'm trying to show the effects of reading a
random byte, reseeking and reinserting it randomly.
 * I don't want to patch the sources, even if I could figure out how,
because I want those beginning programmers to be able to use DJGPP out of
the box on their own systems.

TIA.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019