Equivalent to tempnam in C ++

I need to create random names that I will use to create temporary files in a directory. I am currently using the C tempnam () function for this. My code is in C ++ and would like to use the C ++ equivalent to accomplish the same task. The code should work on both Solaris and Windows.

Does anyone know of such a thing in C ++? Any pointer to this would be greatly appreciated.

+3
source share
5 answers

Try std::tempnamthe header cstdio.;)

The standard C library is still available in C ++ code. For convenience, they provide C ++ wrappers (in headers prefixed with "c" and without extension) and are available in the std namespace.

C (stdio.h tempnam , ++;))

++ , . , char , C . , , , .

- tempnam, ++ , C? , .

+4

, , , :

tempnam (3) , , , , tempnam (3) pathname , , , (2) . . , (2) O_EXCL . , mkstemp (3) tmpfile (3).

+3

, C? ++ C.

+1

tempnam()? libc ? tempnam stdio.h, , , .

+1
#include <cstdio>
using std::tmpnam;
using std::tmpfile;

You should also check this fooobar.com/questions/171936 / ... and avoid race conditions when creating files using mkstemp, so I would recommend using std :: tmpfile

0
source

Source: https://habr.com/ru/post/1709665/


All Articles