How to create a std::ofstream to a temp file?

后端 未结 4 1379
醉梦人生
醉梦人生 2020-12-24 12:45

Okay, mkstemp is the preferred way to create a temp file in POSIX.

But it opens the file and returns an int, which is a file descriptor. F

4条回答
  •  借酒劲吻你
    2020-12-24 13:10

    Maybe this will work:

    char tmpname[256];
    ofstream f;
    sprintf (tmpname, "/tmp/tmpfileXXXXXX");
    int fd = mkstemp(tmpname);
    ofstream f(tmpname);
    

    I haven't tried it, but you can check.

提交回复
热议问题