Suppose I "popen" an executable, I get a FILE*
in return. Furthermore, suppose I'd like to "connect" this file to an istream
object for easier processing, is there a way to do this?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
Sure there's a way, implement your own
istream
that can be constructed from aFILE*
.If you're asking whether there is a standard way to do this, then no.
You can get away by deriving std::basic_streambuf or std::streambuf classes.
Something along these lines:
There is no standard way but if you want a quick solution you can get the file descriptor with fileno() and then use Josuttis' fdstream. There may be similar efforts around but I used this in the distant past and it worked fine. If nothing else it should be a very good map to implementing your own.