Mail Archives: djgpp/1994/09/23/20:55:15
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 -