Saturday, 15 July 2017

html - C++ Change output file name if exists

I'm trying to write HTML output file. The file is written and all is well, but I'd like to know if there is a way to take a string with it's file name, check if that exists and if yes then change that string somehow. So I would never overwrite already existing file.


string outputFile;
cin>>outputFile;
ofstream out;
string path ="..\\data\\"+ outputFile+ ".html";
out.open(path.c_str());

So in this case if outputFile is let's say "Jesus" then I want to do something so if I would run this 3 times I'd have something like Jesus.html, Jesus2.html, Jesus3.html. Doesn't necesarilly have to be numbered like that, just any change to that string will do. Is this even possible? I tried this using
tmpnam()
but I don't really understand how it's supposed to work and if it can even be used.


Thanks for any help

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...