From 7777516505893006531
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,975e78bef1b26ee8
X-Google-Attributes: gidf78e5,public
From: jkanze@otelo.ibmmail.com
Subject: Re: iostream -> FILE*
Date: 1998/05/26
Message-ID: <6kert4$5bj$1@nnrp1.dejanews.com>#1/1
X-Deja-AN: 356686143
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <3561480D.18DAE41D@acco.net> <6jv28m$u37$1@nnrp1.dejanews.com> <m3emxmflxc.fsf@gabi-soft.fr> <01bd8828$4cf2eca0$8a1ec2d0@porky>
Originator: clamage@taumet
X-NNTP-Posting-Host: 195.75.80.132
X-UID: 0000000001
X-Status: $$$T
X-Http-User-Agent: Mozilla/4.03 [de] (WinNT; I)
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Tue May 26 16:50:42 1998 GMT
Newsgroups: comp.std.c++


In article <01bd8828$4cf2eca0$8a1ec2d0@porky>,
  "P.J. Plauger" <pjp@dinkumware.com> wrote:
>
> J. Kanze <kanze@gabi-soft.fr> wrote in article
> <m3emxmflxc.fsf@gabi-soft.fr>...
> > dietmar.kuehl@claas-solutions.de writes:
> >
> > |>  In article <3561480D.18DAE41D@acco.net>,
> > |>    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.
> >
> > On the other hand, it shouldn't be that difficult to cobble up a
> > FILEstreambuf, which reads and writes from a FILE*.  Total
> > synchronization for output would be trivial, but I'm not sure it is even
> > possible for input -- you'd need some sort of command to tell the
> > FILEstreambuf to synchronize before starting FILE* input.

    [...]

> Take a look at <fstream> in VC++ V4.2/V5.0. It supports, as a conforming
> extension, the constructor:
>
> basic_filebuf(FILE * = 0);
>
> In other words, you can construct a file buffer that works with an existing
> FILE object from the C library. Even better, the member functions in
> basic_streambuf (see <streambuf>) are jiggered to perform I/O directly to
> and from the C buffer. The net effect is that you get synchronization for
> free and a transfer rate that approaches that of a buffered copy loop in C
> (which in turn approaches that of a buffered copy loop in assembly
> language). You can even do seeks, either from C or C++. And you can
> do both reads and writes to the same file buffer, provided you honor the
> requirement that a seek must intervene between read and write, or
> between write and read.

This is, of course, the ideal solution.  It is only really available,
however, if you can control both the C and C++ library implementation --
which is not the case of most of us.

If you're not worried about portability, and willing to risk incompatiblity
with future releases of your compiler, you might be able to hack something
similar by looking at the expansion of the macros in stdio.h.  It's not
something I'd recommend.  (Lobbying your compiler vendor to provide this
extension, however, sounds like a good idea though.)

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient�e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


[ 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              ]




