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

后端 未结 7 2124
情歌与酒
情歌与酒 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:55

    There's a good chance your compiler offers a FILE-based fstream constructor, even though it's non-standard. For example:

    FILE* f = fdopen(my_fd, "a");
    std::fstream fstr(f);
    fstr << "Greetings\n";
    

    But as far as I know, there's no portable way to do this.

提交回复
热议问题