If I understand you correctly, you want your program to create a new (different) text file each time?
So for instance, if your program wants to create a file
foo.txt, but
foo.txt already exists, then create
bar.txt instead?
In any case, your program needs to know what to name the file.
That being said, it's possible to use a loop and
std::ostringstream to create files
foo1.txt,
foo2.txt,
foo3.txt, etc.
Since you want it to create a new file each time the program is run, you can do this:
initialize i to 1
while fooi.txt exists (replace i with the value of i)
increment i
create file fooi.txt |
You can converting numbers to strings using one of these methods:
http://www.cplusplus.com/articles/D9j2Nwbp/
For checking whether a file exists or not, you could try opening it up in read-only mode (perhaps using an
std::ifstream), and then checking whether the file is actually open or not.