インデントが切れてました失礼…

class tmpfilebuf : public filebuf
{
 public:
  tmpfilebuf()
  {
    FILE* fp = tmpfile();
    int fd = fileno();
    int mfd = dup(fd);

    ::fclose(fp);
    ::close(fd); // これは不要かもしれない…

    this->attach(mfd);
  }

  tmpfilebuf(const tmpfilebuf& src)
  {
    int mfd = dup(src.fd());
    this->attach(mfd);
  }

  virtual ~tmpfilebuf()
  {
    ::close(this->fd());
  }
};