* Bug in g++ ? (binary writing to file)
@ 1998-05-06 11:22 Armin Ollig
0 siblings, 0 replies; only message in thread
From: Armin Ollig @ 1998-05-06 11:22 UTC (permalink / raw)
To: axp-list
[-- Attachment #1: Type: text/plain, Size: 2157 bytes --]
ok,
here's a very short and simple proggy for writing some numbers to a file
*binary*. The output is a double.dat file with a size of 0 bytes, hence
nothing at
all was written. The proggy is from an (ansi) C++ book.
It works as expected with Borlands C++ 5.0 under $95.
If i debug the problem i get:
0x40066828 in ofstream::open () at fstream.h:87
fstream.h:87: No such file or directory.
Is this a bug or am i just mad ???
However, it works without a problem if i use ascii io, but refuses to
work with "ios::binary".
I compile with "g++ -o foo01 foo01.c++".
My system is a RH5; PC164 21164; Kernel 2.0.33; gcc version 2.7.2.3
...what gdb reports:
(gdb) list
1 #include <iostream.h>
2 #include <stdlib.h>
3 #include <fstream.h>
4 void main(void)
5 {
6 ofstream target;
7 target.open("double.dat", ios::binary);
8 if (!target)
9 {
10 cerr << "could not open file for writing" << endl;
(gdb) break 7
Breakpoint 1 at 0x8048689: file foo01.c++, line 7.
(gdb) run
Starting program: /home/armin/foo01
step
Breakpoint 1, main () at foo01.c++:7
7 target.open("double.dat", ios::binary);
(gdb) step
0x40066828 in ofstream::open () at fstream.h:87
fstream.h:87: No such file or directory.
(gdb) step
Program exited normally.
(gdb)
...my programm:
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
void main(void)
{
ofstream target;
target.open("double.dat", ios::binary);
if (!target)
{
cerr << "could not open file for writing" << endl;
exit(-1);
}
double d=1.0;
for (int i=0; i < 20; i++, d*=1.1)
target.write((char *) &d, sizeof(d));
target.close () ; // if you want...
}
any suggestions welcome :))
thanks in advance,
best regards,
--armin
--
---------------------------------------------------------------------
| Armin Ollig UNIX Systems Administration armin@tops.net |
| |
| If god is dead who will save the queen ? |
---------------------------------------------------------------------
[-- Attachment #2: Type: message/rfc822, Size: 2386 bytes --]
From: Armin Ollig <armin@tops.net>
To: axplist@redhat.com
Subject: Bug in g++ ? (binary writing to file)
Date: Tue, 05 May 1998 13:36:06 +0000
Message-ID: <354F15C6.AAEB22@tops.net>
ok,
here's a very short and simple proggy for writing some numbers to a file
*binary*.
The output is a double.dat file with 0 bytes of lenth, hence nothing at
all
was written. The proggy is from an (ansi) C++ book. If i debug the
problem i
get: 0x40066828 in ofstream::open () at fstream.h:87
fstream.h:87: No such file or directory.
Is this a bug or am i just mad ???
However, it works without a problem if i use ascii io, but refuses to
work with
ios::binary.
I compile with "g++ -o foo01 foo01.c++".
My system is a RH5 PC164 21164; Kernel 2.0.33; gcc version 2.7.2.3
...what gdb reports:
(gdb) list
1 #include <iostream.h>
2 #include <stdlib.h>
3 #include <fstream.h>
4 void main(void)
5 {
6 ofstream target;
7 target.open("double.dat", ios::binary);
8 if (!target)
9 {
10 cerr << "could not open file for writing" << endl;
(gdb) break 7
Breakpoint 1 at 0x8048689: file foo01.c++, line 7.
(gdb) run
Starting program: /home/armin/foo01
step
Breakpoint 1, main () at foo01.c++:7
7 target.open("double.dat", ios::binary);
(gdb) step
0x40066828 in ofstream::open () at fstream.h:87
fstream.h:87: No such file or directory.
(gdb) step
Program exited normally.
(gdb)
...my programm:
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
void main(void)
{
ofstream target;
target.open("double.dat", ios::binary);
if (!target)
{
cerr << "could not open file for writing" << endl;
exit(-1);
}
double d=1.0;
for (int i=0; i < 20; i++, d*=1.1)
target.write((char *) &d, sizeof(d));
}
thanks in advance,
best regards,
--armin
--
---------------------------------------------------------------------
| Armin Ollig UNIX Systems Administration armin@tops.net |
| |
| If god is dead who will save the queen ? |
---------------------------------------------------------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1998-05-06 11:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-05-06 11:22 Bug in g++ ? (binary writing to file) Armin Ollig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox