Question: Why doesn't this code work?
vector <ofstream> vout ; ofstream test("blah") ; vout.push_back(test)
.
One minute response: Because it doesn't make sense to make a copy of an open file stream, the file-stream copy constructor is private. As was mentioned in class, containers make copies of everything all the time, which means the container element type must support a public copy constructor. If you really want to do something like this, you can use pointers:
vector <ofstream *> vout ; vout.push_back(new ofstream("blah"))
but, of course, you're just begging for trouble if you do that.
This page last modified on 16 July 2003.