D
DJ
I have been attempting to move some code that i have into an object from my
main program. Everything is working fine until i try to open an ifstream in
the object. since i want the file access across the object i have declared
it as follows:
class myclass{
private:
ifstream infile;
public:
myclass(string sourcepath);
};
myclass::myclass(string sourcepath)
{
infile.open(sourcepath.c_str(), ios::in); //this causes an error.
if (!infile) cout << "ERROR" << endl;
};
/////////////////////////////////////////////////////////////////
elsewhere....in main()
myclass f("in.txt");
//////////////////////////////////////////////////////////////////
output for this instance of the myclass will cause:
ERROR
Is there something i am missing? Does it need to be static or something?
Like i said the code worked in the main program just fine.
Thanks for any help.
David
main program. Everything is working fine until i try to open an ifstream in
the object. since i want the file access across the object i have declared
it as follows:
class myclass{
private:
ifstream infile;
public:
myclass(string sourcepath);
};
myclass::myclass(string sourcepath)
{
infile.open(sourcepath.c_str(), ios::in); //this causes an error.
if (!infile) cout << "ERROR" << endl;
};
/////////////////////////////////////////////////////////////////
elsewhere....in main()
myclass f("in.txt");
//////////////////////////////////////////////////////////////////
output for this instance of the myclass will cause:
ERROR
Is there something i am missing? Does it need to be static or something?
Like i said the code worked in the main program just fine.
Thanks for any help.
David