Converting C FILE to C++ fstream
I have an application where I am using popen:
FILE *popen(const char *command, const char *type);
In a previous contract, we had a way to convert FILE * to fstream
(instream or ostream). I prefer that my application be as pure C++ as
possible. In a quick search, I have not found a safe way to do it.
As an alternative, I could design my own class with fork()/exec() and
pipes, but it's not that important since I can easily use popen(), and
the other C stdio functions from C++.
--
Jerry Feldman
Jerry Feldman
I have an application where I am using popen: FILE *popen(const char *command, const char *type);
In a previous contract, we had a way to convert FILE * to fstream (instream or ostream). I prefer that my application be as pure C++ as possible. In a quick search, I have not found a safe way to do it.
If you're going to use gcc, see /usr/include/g++/ext/stdio_filebuf.h for a way to use a FILE * as a filebuf which you can use to construct a fstream. Note that the contents of this header is in namespace __gnu_cxx. Philipp
On Sat, 05 Jul 2003 23:40:01 +0200
Philipp Thomas
If you're going to use gcc, see /usr/include/g++/ext/stdio_filebuf.h for a way to use a FILE * as a filebuf which you can use to construct a fstream. Note that the contents of this header is in namespace __gnu_cxx. Thanks. I'll check that out.
--
Jerry Feldman
participants (2)
-
Jerry Feldman
-
Philipp Thomas