How to construct a c++ fstream from a POSIX file descriptor?

后端 未结 7 1988
情歌与酒
情歌与酒 2020-11-22 12:36

I\'m basically looking for a C++ version of fdopen(). I did a bit of research on this and it is one of those things that seems like it should be easy, but turns out to be v

7条回答
  •  渐次进展
    2020-11-22 12:54

    AFAIK, there is no way to do this in standard C++. Depending on your platform, your implementation of the standard library may offer (as a nonstandard extension) a fstream constructor taking a file descriptor (This is the case for libstdc++, IIRC) or a FILE* as an input.

    Another alternative would be to use a boost::iostreams::file_descriptor device, which you could wrap in a boost::iostreams::stream if you want to have an std::stream interface to it.

提交回复
热议问题