I'm having trouble with a function that reads in data from an external txt file. inFile.fail() keeps returning true which really baffles me because I have the exact same code and am using the exact same file as an earlier assignment but it still works even now.
void readIn(string file, Movie *movies, int *size)
{
string inName, inType;
int inYr, inMins;
double inCost;
int nothing = 0; // just for skipping over movie count at top of file
// since we've already obtained that data
ifstream inFile;
inFile.open(file.c_str());
if (inFile.fail()){
cout << "File failed to load. Press enter to quit. ";
cin.get();
cout << endl << endl;
}else{
inFile >> nothing;
for (int i = 0; i < *size; i++){
inFile >> inName;
(movies + i)->setTitle(&inName);
inFile >> inMins;
(movies + i)->setLength(&inMins);
inFile >> inType;
(movies + i)->setGenre(&inType);
inFile >> inYr;
(movies + i)->setYear(&inYr);
inFile >> inCost;
(movies + i)->setPrice(&inCost);
}
}
inFile.close();
}
Again, I actually just copies the function from the old assignment into the new one and modified it. I'm using the same txt file and the old one still works but the new one always fails.
Oh, and I've checked that I have the right directives at the top of the code: