Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何创建和操作 ifstreams 的向量?
像这样的东西,除了这不起作用:
vector<ifstream> Files(10, ifstream()); Files[0].open("File");
您不能将ifstreams 存储在 a 中std::vector,因为您无法创建它们的副本。
ifstream
std::vector
您可以通过存储指针来完成类似的事情。在这种情况下,我建议您使用某种指针容器来确保删除这些 ifstream。
我能想到的最接近的是vector<shared_ptr<ifstream> >-您不能将ifstreams 放入向量中,因为它们不可复制。
vector<shared_ptr<ifstream> >