Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
tmpnam() - Create Temporary Filename - I/O Function - C++ Tutorial

tmpnam() - I/O Function

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

Explanation

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.

Syntax:


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);
}
else
{
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