www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/23/20:55:15

Date: Fri, 23 Sep 94 16:34:32 -0400
From: Yadin Y. Goldschmidt <yygold AT yadin DOT phyast DOT pitt DOT edu>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: bug (?) in djgpp
Cc: yygold AT yadin DOT phyast DOT pitt DOT edu

The following c++ program was taken from a book and compiles and  
executes fine on a unix station (NeXT). However with djgpp on a PC it  
compiles with no warning, but when executed gives a segmentation  
fault. Any clues?

// an example of reading and writing binary buffers to/from a file
# include <iostream.h>
# include <fstream.h>
# include <std.h>
# include <stdio.h>

main()
{
        ofstream out("test");
        if(!out) {
          cout << "cannot open output file. \n";
          return 1;
        }

	double num=100.45;
	char str[]="This is a test";

	out.write((char *) &num, sizeof(double));
	out.write(str,strlen(str));

	out.close();

	return 0;
}


- Raw text -


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