Connecting Tech Pros Worldwide Help | Site Map

FILE * and fstream

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 14th, 2006, 07:35 PM
Adrian
Guest
 
Posts: n/a
Default FILE * and fstream

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.



TIA

--

Adrian

Think you know a language? Post to comp.lang... and find out!

  #2  
Old November 14th, 2006, 09:15 PM
BobR
Guest
 
Posts: n/a
Default Re: FILE * and fstream


Adrian wrote in message ...
Quote:
>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?
Quote:
>
>I seem to remember a nice way of wrapping FILE * in a class from Herb
Sutters books, but I dont have them with me.
Quote:
>

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


  #3  
Old November 15th, 2006, 02:55 PM
Tilman Kuepper
Guest
 
Posts: n/a
Default Re: FILE * and fstream

Hi Adrian,
Quote:
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 think it was in Josuttis' book. See here:
http://www.josuttis.com/cppcode/fdstream.html

Best regards,
Tilman



  #4  
Old November 15th, 2006, 07:05 PM
Adrian
Guest
 
Posts: n/a
Default Re: FILE * and fstream

Tilman Kuepper wrote:
Quote:
Hi Adrian,
>
Quote:
>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 think it was in Josuttis' book. See here:
http://www.josuttis.com/cppcode/fdstream.html
Now that I have with me :-) I have been trawling through it, will
check it out.

Thanks


--

Adrian

Think you know a language? Post to comp.lang... and find out!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.