#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Movie
{
private:
ifstream inMovie; //private member variables
void openFile();
void testFile();
void readFile();
public:
Movie(); //constructor
void driver()
{
openFile();
};
};
void Movie::openFile()
{
ifstream inMovie;
inMovie.open("SciFiMovies.txt");
testFile();
readFile();
}
void Movie::testFile()
{
ifstream inMovie;
if (!inMovie.open)
{
cout << "Unable to open the file.";
exit(1);
}
}
void Movie::readFile()
{
ifstream inMovie;
string file;
while (!inMovie.eof)
{
getline(inMovie, file);
cout << file;
}
}
int main()
{
Movie movObj;
movObj.driver();
system("pause");
return 0;
}
Why am I getting an error code? Using the ! typically works for me when I want to test if a file fails to open or when I read a file. Also, the teacher requires that we use several different void functions, which is why the program may look a little weird (with several functions to accomplish a simple task). Any help would be greatly appreciated, thank you.