Topic: How to read or write binary files in C++ with the I/O streams ?


Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1996/07/31
Raw View
In article <4tkrun$48b@news.cict.fr> younes@eis.enac.dgac.fr (Abdelrazak
YOUNES) writes:

|> I would like to know what are the equivalents for "fread" and "fwrite" in
|> C++.

istream::read and ostream::write.
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
                -- A la recherche d'une activiti dans une region francophone
---
[ 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: patrick@broadvision.com (Patrick Horgan)
Date: 1996/08/05
Raw View
In article <4tkrun$48b@news.cict.fr>, younes@eis.enac.dgac.fr (Abdelrazak YOUNES) writes:
> I would like to know what are the equivalents for "fread" and "fwrite" in
> C++.

istream supports various get() methods that map quite closely to read.
ostream supports various put() methods that map quite closely to write.

they support seekp() (seek the get pointer), and seeg() seek the
get pointer().

Any man page or documentation of ostream and istream should tell
you all this and more.  If you want to use an input routine that takes a
count and a delimiter but you don't care about a delimiter, just use EOF
for the delimiter.

--

   Patrick J. Horgan    patrick@broadvision.com   Have horse will ride.
   Opinions mine, not my employer's except by most bizarre coincidence.
---
[ 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: pixi@bloodbath.slaughter.com (maurice s. barnum)
Date: 1996/08/05
Raw View
On 30 Jul 96 12:33:07 GMT, Abdelrazak YOUNES <younes@eis.enac.dgac.fr> wrote:
:I would like to know what are the equivalents for "fread" and "fwrite" in
:C++.

    if by "in C++" you mean "using iostreams instead of stdio",
    istream::read() and ostream::write(), respectively.

 --xmsb
---
[ 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: younes@eis.enac.dgac.fr (Abdelrazak YOUNES)
Date: 1996/07/30
Raw View
I would like to know what are the equivalents for "fread" and "fwrite" in
C++.
I couldn't any help in Borland documentation, neither in gcc one. They just
say that the iostreams libraries can read or write binary files but they
don't say how.

I need to know this because I don't want to use stdio.h which is most of the
time incompatible with iostream.h .

I would appreciate any help, so please could someone answer to my question?

Thanks in advance,
   A. Younes

+-------------------------------------------------------------+
| Abdelrazak Younes   E-Mail: younes@monstre.eis.enac.dgac.fr |
| Ecole Nationale de l'aviation civile  (Toulouse, FRANCE)    |
| Laboratoire de Traitement du Signal et de Telecommunication |
| Tel   : 62 17 42 78                FAX: 62 17 42 70         |
---
[ 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                             ]