|
-
June 20th, 1999, 09:49 PM
#1
Creating temp files with unique names.
In my MFC MDI, when the user opens a file the program needs to create a temporary file. So because it is MDI I need to create a different temporary file name for each file opened, but I don't know how to do this. At the moment, my temp. file is called temp.txt, but this means that if the user opens a second input file my program crashes. How can I create different filenames for these temp files? I would like to use filenames of either of following formats: <inputfile>.tmp or temp1.txt, temp2.txt .
Thank you,
Sean.
-
June 21st, 1999, 08:58 AM
#2
Re: Creating temp files with unique names.
Check out the WIN32 function GetTempFileName or the ANSI C function tmpnam.
You can also roll your own by building a string out of a a fixed prefix and a number that you keep incrementing. Before you create the next temp file search the directory you are writing the files to and if there is already a file with the name you want to use then increment the number. Much simpler to use one of the above functions.
Josh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|