0
我來自PHP。在PHP中,我們可以返回文件句柄到一個變量:C++返回文件連接到一個成員,所以可以被同一類的其他方法使用
class FileHandler
{
private $_fileHandler;
public function __construct()
{
$this->_fileHandler = fopen('log.txt', 'a');
}
public function writeToFile($sentence)
{
fwrite($this->_fileHandler, $sentence);
}
}
我現在面臨的問題是,在C時,我希望它分配給成員,所以我可以通過我的課++中使用它給錯誤
FileUtils::FileUtils()
{
// I do not what type of variable to create to assign it
string handler = std::ofstream out("readme.txt",std::ios::app); //throws error.
// I need it to be returned to member so I do not have to open the file in every other method
}