如何在c ++类</ifstream>中定义vector <ifstream>

时间:2013-07-24 09:22:33

标签: c++ vector fstream

我在课堂上需要一个矢量成员:

class A
{
private:
vector<ifstream> _files;
public:
bool addFile(const string& filePath);
};

bool A::addFile(const string& filePath)
{
ifstream ifile(filePath.c_str());
_files.push_back(ifile);//but errors;
}

如何通过成功编译完成此课程;

现在我的解决方案是使用矢量。这可以吗?或一些潜在的危险?

1 个答案:

答案 0 :(得分:2)

STL容器需要元素 CopyConstructible 可分配std::ifstream不可复制。您需要使用指向std::ifstream的智能指针。