Topic: open a file with binary mode


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/05/07
Raw View
In article 01I4DU2VS15E8ZM7FW@ubaclu.unibas.ch, song@iso.iso.unibas.ch (Song Ji
n) writes:
>I knew that to open a binary file, I've to say:

>ofstream s("filename", ios::out|ios::binary);

>It worked with Borland C. But with GNU C++ 2.7, it doesn't work, complains
>that binary is not a member of ios. I finally found that in iostreambuf.h,
>it is defined as ios::bin. Is the bin instead of binary a part of new
>standard of C++?

The spelling in the draft standard is "binary".

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: ccwf@thales.klab.caltech.edu (Charles Fu)
Date: 1996/05/08
Raw View
In article 01I4DU2VS15E8ZM7FW@ubaclu.unibas.ch, song@iso.iso.unibas.ch (Song Jin) writes:
>>I knew that to open a binary file, I've to say:

>>ofstream s("filename", ios::out|ios::binary);

Besides issues of how "binary" is spelled, you'll also want to specify
               ios::out | ios::trunc | ios::binary
or
               ios::out | ios::app | ios::binary

I have found that different implementations will act differently if
neither truncate nor append have been explicitly specified.

Is the committee intending on leaving this case as undefined behavior?
My copy of the draft has a note after Table 19: File Open Modes which
simply says

    The table omits many cases, including the common case of out.

-ccwf
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: song@iso.iso.unibas.ch (Song Jin)
Date: 1996/05/06
Raw View
I knew that to open a binary file, I've to say:

ofstream s("filename", ios::out|ios::binary);

It worked with Borland C. But with GNU C++ 2.7, it doesn't work, complains
that binary is not a member of ios. I finally found that in iostreambuf.h,
it is defined as ios::bin. Is the bin instead of binary a part of new
standard of C++?

Thanks in advance.

Song JIN
song@iso.iso.unibas.ch
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]