2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / docs / html / 27_io / binary_iostreams_kanze.txt
blob65d79c996c5d3b0bb4f97c1da31195300df05e8e
2 From: James Kanze <kanze@gabi-soft.de>
3 Newsgroups: comp.lang.c++.moderated
4 Subject: Re: binary iostreams ?
5 Date: 3 Feb 2001 14:28:19 -0500
6 Message-ID: <86lmro86qp.fsf@alex.gabi-soft.de>
8 "Plinio Conti" <plinio.contiNO@SPAMMINGmclink.it> writes:
10 |>  Why std c++ library stream classes are only text-oriented?
12 Because that is the only universally recognized format.
14 |>  I mean, if I want to write an int, a float, etc. AS IT IS I can't
15 |>  use streams, because they write and read a human readable text
16 |>  format of numbers.
18 Correct.
20 |>  Does anyone know how to solve the problem?
22 It depends on what you really want to do.  If you are just dumping a
23 block of memory to disk, in order to free up memory, and will reread it
24 later in the same run of the same program, ostream::write and
25 istream::read are what you need.  Note, however, that this ony works 1)
26 in the same run of the same program, and 2) for PODs without pointers.
28 If you are writing something that will be read by another program, or a
29 later run of the same program, you'll have to define a specific format
30 to use, and implement streams to input and output that.  If you are
31 writing something that will be read by an existing program, or be
32 transmitted over a network to another machine, you will have to find out
33 what protocol is expected, and adher to it.
35 |>  Any public library?
37 Not that I know of.  I think that there is a library somewhere that
38 outputs in format RPC, or maybe some Internet format.
40 |>  What do you think about this choice?
42 What other choice is possible?  It's not reasonable to ask the standard
43 to support all binary formats, and it's not reasonable for it to favor
44 any one of them.  Given that, what else can you do.
47 James Kanze                               mailto:kanze@gabi-soft.de
48 Conseils en informatique orientée objet/
49                    Beratung in objektorientierter Datenverarbeitung
50 Ziegelhüttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627