Topic: FILE* and iostreams


Author: "J.Barfurth" <techview@bfk-net.de>
Date: 1999/11/27
Raw View

Tehmul Ghyara <niitrmo-remove-me-@vsnl.com> schrieb in im Newsbeitrag:
81hgmq$5ek$1@news.vsnl.net.in...
> Is there any portable way to attach a C-style FILE * to a stream,  i.e. I

Short answer: yes, but not as simple as you might hope.

Longer answer:
    Some implementations of iostreams allow you to do it easily. They
provide a constructor for std::filebuf (sometimes also for
std::[i|o]fstream) that takes a FILE* parameter. But that is not portable.

The portable way is: write your own streambuf-derived class that does its
work thru a FILE*. Attach that to an [i|o]stream using basic_ios::rdbuf()

For more information use deja.com's power search feature to search on
    news:comp.lang.c++[.moderated]
for threads discussing this question. There are enough of them to warrant a
FAQ (IMHO).

-- J   rg Barfurth




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






Author: "Tehmul Ghyara" <niitrmo-remove-me-@vsnl.com>
Date: 1999/11/26
Raw View
Is there any portable way to attach a C-style FILE * to a stream,  i.e. I
want to associate a FILE * pointers with an ifstream.  I read somewhere that
cin gets its input from the same stream as stdin.  Would that imply there's
a way to associate a FILE* pointer to any of the classes in the iostream
hierarchy?

TIA
Tehmul

strip the -remove-me- for the actual email address.

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