From 5296497920240114626
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,975e78bef1b26ee8
X-Google-Attributes: gidf78e5,public
From: ajrobb@ecr.mu.oz.au (Andrew_J ROBBIE)
Subject: Re: iostream -> FILE*
Date: 1998/05/21
Message-ID: <6k0nmi$sfb$1@mulga.cs.mu.OZ.AU>#1/1
X-Deja-AN: 355295359
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <3561480D.18DAE41D@acco.net> <6jv28m$u37$1@nnrp1.dejanews.com>
Originator: clamage@taumet
X-Nntp-Posting-Host: gromit.ecr.mu.oz.au
X-UID: 0000000001
X-Status: $$$$
Organization: Computer Science, The University of Melbourne
Newsgroups: comp.std.c++


dietmar.kuehl@claas-solutions.de wrote:
:   Marc Dzaebel <marc@acco.net> wrote:
: > I have C I/O-functions operating on FILE*stream. Is it possible to get a
: > FILE pointer
: > from any iostream (e.g. istrstream)?

: No. It is not even possible to get a 'FILE*' from an '[io]fstream'.
: However,
: there are some libraries (eg. the current libg++) where you can use an
: arbitrary 'streambuf*' when a 'FILE*' is required (at least, libg++ had a
: feature like this). But, of course, this is not a portable feature.

This has come up before (and it keeps coming up in my code) - you have a
piece of standard, vanilla, ANSI/ISO C code, which uses FILE* to do I/O,
and you want to interface it to a piece of C++.

Now, it seems to me that a conversion from FILE* to fstream (and vice
versa) would be really useful. No doubt there are problems with buffering,
etc, but are they that bad?

The other thing which crops up is the problem of finding the file
descriptor from a C++ stream object. At this stage, people will start
saying "but DOS doesn't have file descriptors, that wouldn't be
portable, go away". And then they say totally unrealistic things
like "don't use fstat to calculate file size, count the number of
bytes in it".

But huge amounts of code are written for un*x systems - systems for
which C++ programmers need a standard way of doing things. Couldn't
there be stream specialisations for each API? And couldn't the
standard provide an 'example' specialisation for posix-type systems?
Sure, compilers can provide extensions, but can't compiler vendors
be guided in the same direction?

Regards,
Andrew



[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




