"Aviv Ben-Yosef" <av*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I've been wondering whether or not there's a way to start writing to an
ofstream and then save it under a specific filename, or must it be done
in the first hand with fstream::open ?
If so, what is the ``cleanest'' way of doing so?
Opening a temporary file and later changing the file's name?
Is there a portable way of doing this?
If the contents can fit the memory, and your implementation of ostringstream
is not too slow, you can write to an ostringstream first, and then create
the file and save the contents of the ostringstream.
ostringstream contents;
contents << /* ... */;
ofstream file(/* ... */);
file << contents.str();
I think there is a faster way of achieving the last step, which involves the
streams' buffers, not the streams themselves...
Ali