【发布时间】:2013-12-21 15:01:02
【问题描述】:
我的班级必须有 ifstream 文件。
我不知道如何在类头中呈现它
答:
class MyClass
{
...
ifstream file;
...
}
乙:
class MyClass
{
...
ifstream& file;
...
}
我知道 ifstream 必须在 decalation 中获取路径,那我该怎么做呢?
还有如何用它打开文件?
编辑:
我想要第一种方式,但我该如何使用它的语法?
假设这是标题(部分)
class MyClass
{
string path;
ifstream file;
public:
MyClass();
void read_from_file();
bool is_file_open();
...
}
功能
void MyClass::read_from_file()
{
//what do I do to open it???
this->file.open(this->path); //Maybe, IDK
... // ?
}
【问题讨论】:
标签: c++ function class ifstream