How can I create and manipulate a vector of ifstreams?
Something like this, except this doesn't work:
vector<ifstream> Files(10, ifstream());
Files[0].open("File");
How can I create and manipulate a vector of ifstreams?
Something like this, except this doesn't work:
vector<ifstream> Files(10, ifstream());
Files[0].open("File");
You cannot store ifstream
s in a std::vector
, because you can not create copies of them.
You can accomplish something similar by storing pointers instead. In that case, I recommend you use some sort of a pointer container to make sure that those ifstreams get deleted.
The closest I can think of is vector<shared_ptr<ifstream> >
— you can't put ifstream
s in vector as they're not copy-constructible.