我需要像这样的类中的 vector 成员:
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;
}
如何成功编译完成本类(class);
现在我的解决方案是使用 vector 。这可以吗?或者一些潜在的危险?
最佳答案
STL 容器需要元素是 CopyConstructible 和 Assignable 。 std::ifstream
不可复制。您需要使用指向 std::ifstream
的智能指针。
关于c++ - 如何在 C++ 类中定义 vector <ifstream>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829961/