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 <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Jerry Feldman <gaf@blu.org> [Sat, 5 Jul 2003 13:32:47 -0400]:
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 <philipp.thomas@t-link.de> wrote:
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 <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
participants (2)
-
Jerry Feldman
-
Philipp Thomas