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
char tempFileName[20]; // name only valid till next invocation of tempFileOpen
ofstream tempFile;
void tempFileOpen()
{
strcpy(tempFileName, "/tmp/XXXXXX");
mkstemp(tempFileName);
tempFile.open(tempFileName);
}
This code works for me with GCC/libstdc++6 4.8.4 and Clang 3.9 as well. Thanks to the other replies as well which were helpful to me.