Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fstream -> FILE*

0 views
Skip to first unread message

barcaroller

unread,
Nov 28, 2008, 8:11:26 PM11/28/08
to

Is it possible to somehow get a FILE* file pointer from an fstream object?
The reason I'm asking is that I have C++ code that now needs to link to a C
library which requires FILE* file pointers.


Zjargands

unread,
Nov 29, 2008, 2:00:02 AM11/29/08
to

I don't believe you can. As a class, fstream has no reason to use a
FILE* internally, it can use whatever it wants. It should be trivial to
extract the open file name however, and then reopen the file using the c
library. Make suer you set your put and get pointers for the file to the
same place they are in the fstream.


signature.asc

Hendrik Schober

unread,
Nov 29, 2008, 5:53:19 AM11/29/08
to

No. To portably do this, you'll have to write your own file
stream buffer which is implemented in terms of 'FILE*' and
provides a means to get at the underlying 'FILE*'. It's not
trivial to do this, but it isn't all that hard either.
If non-portable is enough for you you can search for an std
lib implementation for your platform that does this. There
might be one.

Schobi

0 new messages