Whenever I used tmpnam my g++ compiler cribbed that its dangerous to use tmpnam and must use mkstemp. But mkstemp returned file id and as my language is C++, i never knew how to use the C file ids with C++ fstreams. Then I found out from the man page of fstream that the following can be done!,
char *tmpFileName= strdup("/tmp/tmpfileXXXXXX");
if(mkstemp(tmpFileName) == -1)
throw runtime_error("temporary file cannot be created");
ofstream out(tmpFileName);
Enjoy C++
Recent Comments