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