Adrian wrote in message ...
>Does anyone has some advice on how to use C FILE *'s safely in C++
I have c style library functions that require a FILE * but I would prefer
the exception safe fstreams. Is there anyway to create a stream from a FILE *
or get the FILE * from a stream?
>
I seem to remember a nice way of wrapping FILE * in a class from Herb
Sutters books, but I dont have them with me.
>
I found this in an **old** GNU C++ iostreams doc:
<">
"C Input and Output"
libio is distributed with a complete implementation of the ANSI C stdio
facility. It is implemented using streambuf objects. See section Wrappers for
C stdio.
// .....
Extensions beyond ANSI:
* A stdio FILE is identical to a streambuf. Hence there is no need to worry
about synchronizing C and C++ input/output--they are by definition always
synchronized.
* If you create a new streambuf sub-class (in C++), you can use it as a FILE
from C. Thus the system is extensible using the standard streambuf protocol.
"Wrappers for C stdio"
A stdiobuf is a streambuf object that points to a FILE object (as defined by
stdio.h). All streambuf operations on the stdiobuf are forwarded to the FILE.
Thus the stdiobuf object provides a wrapper around a FILE, allowing use of
streambuf operations on a FILE. This can be useful when mixing C code with
C++ code.
// .......
</">
Don't know if that could help you. Maybe it could narrow your search.
--
Bob R
POVrookie