ifstream / filebug / FILE*

M

Mathieu Malaterre

Hi,

I am tryig to convert part of a c++ IO library. Right now I am removing
all 'FILE*' and replace them with ifstream.

But I have a problem, after seeking through a stream I have to call the
ijg (jpeg library). Since this is a C library it uses FILE*. My question
is then is there a compatibility layer for ifstream <-> FILE* ?
It should work on non-GNU compiler.

Thanks,
Mathieu
Ps: All I found was:
http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html
 
S

Siemel Naran

Mathieu Malaterre said:
I am tryig to convert part of a c++ IO library. Right now I am removing
all 'FILE*' and replace them with ifstream.

But I have a problem, after seeking through a stream I have to call the
ijg (jpeg library). Since this is a C library it uses FILE*. My question
is then is there a compatibility layer for ifstream <-> FILE* ?
It should work on non-GNU compiler.

I don't think there is a portable way to convert an fstream info a FILE. In
practice, I imagine the std::filebuf class contains within it a priviate
member FILE *, but it's not required by the standard nor is the a public
function to get it.
 
J

John Harrison

Hi,

I am tryig to convert part of a c++ IO library. Right now I am removing
all 'FILE*' and replace them with ifstream.

But I have a problem, after seeking through a stream I have to call the
ijg (jpeg library). Since this is a C library it uses FILE*. My question
is then is there a compatibility layer for ifstream <-> FILE* ?
It should work on non-GNU compiler.

Thanks,
Mathieu
Ps: All I found was:
http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html

There is no standard way to convert ifstream to FILE*.

The only way to get the compatibility you want is to write your own stream
classes. These classes would extend the iostream library but also use a
FILE* internally which you can then make accessible.

Extending the iostream library is not too difficult and is a useful
technique to learn. You could find the technique explained in The
C++ Standard Library by Josuttis for instance.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top