Will ofstream:pen(filename) create the file with filename if the said file does not already exist?
Will ofstream:pen(filename) create the file with filename if the said file does not already exist?
ofstream:pen(filename) will create the file if it does not exist. If it does exist, what it does after open WRT the file ptr is dictated by the additional ios::XXX flags you pass in like:
will open it in append mode...Code:ofstream::open(filename, ios::app);
open - C++ Reference
Check out the link for the other permutations..
Thanks.
I had actually already checked out that link before asking the question. I just asked it because it does not mention at that link whether it creates the file or not.
I just wish the C++ IO classes had something similar to the O_EXCL flag for open(). Otherwise it just opens the door to race conditions.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Wow you are right; even though most of my work is C++ nowadays I never used ofstream with any kind of access modifiers. If I needed to manage access to a file handle I just used the lower level calls. That said it would not be that hard to make your own wrapper for it and supply the access modifiers yourself..