Question

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");
Was it helpful?

Solution

The closest I can think of is vector<shared_ptr<ifstream> > — you can't put ifstreams in vector as they're not copy-constructible.

OTHER TIPS

You cannot store ifstreams 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top