I have 10 files need to be open for write in sequence. Can I have one fstream to do this? Do I need to do anything special (except flush()) in between each file or just call open(file1, fstream::out | std::ofstream::app) for a each file and close the stream at the end of all 10 files are written.
I have 10 files need to be open for write in sequence. Can I
Share
You will need to close it first, because calling
openon an already open stream fails. (Which means thefailbitflag is set to true). Noteclose()flushes, so you don’t need to worry about that:Also note, you don’t need to
close()it the last time; the destructor does that for you (and therefore alsoflush()‘s). This may make a nice utility function:And you get: