I am trying to make a pointer to fstream so I can use it in all of my class methods :
class P
{
private:
fstream *fs;
public:
P()
{
fstream fs(filepath, openmode);
this->fs = &fs;
}
};
But it seem to be not pointing to it at all e.g if I write:
fs->is_open()
it will return false, whereas if I write:
fs.is_open()
it will return true.
What is causing this? I also tried to change the pointer to another like fstr but that didn’t work either.
To accomplish what you are asking for, you need to use the
newoperator, like this: