I thought to transform this working code:
ofstream outfile("my_file.txt");
copy(v.begin(), v.end(), ostream_iterator<int>(outfile));
into this:
copy(v.begin(), v.end(), ostream_iterator<int>(ofstream("my_file.txt")));
In other words, I use an "anonymous", or unnamed, version of the ofstream object.
Two questions:
(1) Why does the second attempt fail?
(2) Is the second attempt even good stylistically, or is it better in C++ to keep everything explicitly named? I'm coming from a Python background, where objects are created on the fly all the time.
Thanks!!