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.
fsteam fs(..)? Please don't re-write your code by hand. Please copy-and-paste what you have actually written and handed to a compiler. There's no point in us debugging something that doesn't actually exist...fsteamandfstreamare not the same thing. The code doesn't compile:filepathandopenmodeare not visibly declared. That makes it hard for us to guess what you're really doing.