[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Bug in g++ ? (binary writing to file)
- From: Armin Ollig <armin tops net>
- To: axp-list redhat com
- Subject: Bug in g++ ? (binary writing to file)
- Date: Wed, 06 May 1998 11:22:01 +0000
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 ? |
------------------------------------------------------------------------ Begin Message ---
- 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
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 ? |
---------------------------------------------------------------------
--- End Message ---
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[]