tmpnam() - I/O Function

How is "tmpnam()" used in C++?


tmpnam() is an I/O function which is used to create a unique filename and store it in a array. The size of the array can also be specified in this function. If this function is executed successfully a pointer to the filename is returned, otherwise a null pointer is returned.


Char *tmpnam( char *name);

Example :

#include <stdio.h>
void main()
char* tname ;
if ((tname = tmpnam(NULL)) != NULL)
printf ("%s is the temporary file name.\n", tname);
printf ("Temporary file name not created\n");

Result :

TMP1.$$$ is the temporary file name.

In the above example the "tmpnam()" is used to create temporary filename that is not similar to any
other file.

C++ Tutorial

Ask Questions

Ask Question