delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/26/22:37:04

From: James Coram <jcoram AT pacificnet DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Trouble with a binary ofstream
Date: Sat, 23 Aug 1997 07:37:40 -0700
Organization: CAIS Internet
Lines: 37
Message-ID: <33FEF5B4.BFC007BE@pacificnet.net>
NNTP-Posting-Host: pm3a-23.pacificnet.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am having trouble using a binary ofstream with DJGPP. I get different
results depending on how I compile my program.

When I compile the following code fragment with:
  gxx test.cc
The resulting a.exe fails, aborting at the final assertion.

However, if I compile with:
   gxx -O3 test.cc
The resulting a.exe runs correctly and creates the file "out".

Note also that if I do not use the ios::binary switch, it works either
way.

As far as I know I am running the lastest installation of DJGPP.
Am I doing something wrong, or can others reproduce this bug?

Thanks

/*test.cc*/

#include <stdlib.h>
#include <assert.h>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

int main() {
 ofstream os("out", ios::binary);
 assert(os);
 assert(!os.bad());
 os << "hello" << endl;
 assert(!os.bad());
 return(0);
 }


- Raw text -


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