Hi everyone. I am just starting out on my assignment on classes. We havent long learnt about them so I am struggling a little on how to do the following.
Below is a small part of the definition of the class.. I have not provided all of it as I dont have questions on the rest of it.... I was wondering how I am supposed to open a txt file in the class constructor target....
So far I have tried and failed. I know I have it wrong but I was hoping someone could point me in the right direction :-)
I will definately be asking my tutor for help this week in class but I would really like to make a start on it!
Thx in advance
K.
Below is a small part of the definition of the class.. I have not provided all of it as I dont have questions on the rest of it.... I was wondering how I am supposed to open a txt file in the class constructor target....
Code:
class target { // Definition for class target // Class target contains the internal logic for the game of target // (user interaction is outside the class in application program) // public: target(); // default constructor // Opens small default dictionary ("dict.txt") and reads words into // vector wordList // Default dictionary contains only lower case words of length 4-9 // Sets centreLetter and otherLetters to spaces.
I will definately be asking my tutor for help this week in class but I would really like to make a start on it!
Code:
target :: target() // default constructor // Opens small default dictionary ("dict.txt") and reads words into // vector wordList // Default dictionary contains only lower case words of length 4-9 // Sets centreLetter and otherLetters to spaces. { ifstream infile; string fname; int data; infile.open(fname.c_str()); if (infile.fail()) { cout << "File not found " << endl; return EXIT_FAILURE; } infile >> data; }
K.
Comment