As far as I know, there's no C++ equivalent for popen() and many other C functions, and I like using C++ as much as possible... Is there any way to convert a FILE* stream to a C++ stream like std::istream so I can use things like std::getline()...?
Printable View
As far as I know, there's no C++ equivalent for popen() and many other C functions, and I like using C++ as much as possible... Is there any way to convert a FILE* stream to a C++ stream like std::istream so I can use things like std::getline()...?
Behind the scenes there is probably a FILE * somewhere inside the istream. But you probably can't get to that in a public way.
--
Mats
Of course, STL is implementation defined, but in MSVC, C++ I/O is just a wrapper for C I/O, but you can't access the whole "C," so in either case you can't do that.
Many standard libraries just wrap C I/O, but this is in no way required. And very few provide a way of getting at the FILE*.
There are some alternatives. You could write your own stream buffer to wrap FILE*s. Or you could use the (not wholly complete) Boost/GSoC2006 library Boost.Process.
Damn... OK, I guess I'll just have to write my own getline( FILE*, std::string& ) function.