This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++ [io]fstream cannot open file in binary mode (g++ and egcs)
- To: gcc-bugs at gcc dot gnu dot org
- Subject: libstdc++ [io]fstream cannot open file in binary mode (g++ and egcs)
- From: "Leonid Pauzner" <uue at pauzner2 dot dnttm dot rssi dot ru>
- Date: Wed, 19 Jan 2000 22:52:25 +0300 (MSK)
Hi.
I run into the following problem with two compilers
on two different platforms:
1) gpp 2.95.1 on DOS (DJGPP port, on a plain i386/DOS 6.22 machine) and
2) g++ on Linux/i386 (one ships with RedHat 6.1 Linux: egcs-2.91.66)
I can not open fstream in BINARY mode,
e.g. I got zero size file from the sample program below.
#include <iostream>
#include <fstream>
int main (int argc, char *argv[])
{
ofstream fpw (argv[1], ios::binary);
for (int i=0; i<256; i++) {
fpw.put( ((char)i) );
}
}
Without "ios::binary" it is OK, but file opened in text
mode which have a difference on a DOS machine, sure.
Info page says one should be ios::bin which doesn't work either; and
Strausrup' "The C++ Programming Language, 3rd ed." says it should be
"ios_base::binary" which will not compile on g++ at all.
After some experimentation I found out that
ofstream fpw (argv[1], ios::binary | ios::out);
will work properly, but seems excessive when ofstream declared
explicitely.
The same thing with
ifstream fp (somename, ios::binary);
vis
ifstream fp (somename, ios::binary | ios::in);
Seems heavily undocumented behaviour.
Sincerely,
Leonid.