explicit basic_ofstream(int fd);
explicit basic_ofstream(const char *s,
ios_base::openmode mode =
long protection = 0666);
I was familiar with the second usage but the first usage was new to me...So one can easily use ofstream with mkstemp as shown below.
char *tmpFileName= strdup("/tmp/tmpfileXXXXXX");
if(mkstemp(tmpFileName) == -1)
throw runtime_error("temporary file cannot be created");