im trying to parse a file. however, the ifstream object keeps failing. in my parsing header file i have this:
class ParseDFA {
public:
bool stop_program = false;
std::ifstream dfa_file;
ParseDFA(std::string parse_filename);
};
in my parsing cpp file i have this:
ParseDFA::ParseDFA(std::string parse_filename) {
dfa_file.open(parse_filename, std::ifstream::in);
if (dfa_file.fail()) {
stop_program = true;
}
}
and in my main.cpp file i have this:
std::string filename = "no000.dfa";
ParseDFA *dfa_file = new ParseDFA(filename);
if (dfa_file->stop_program) {
std::cout << "Error opening file." << std::endl;
return 0;
}
my output:
Error opening file.
I know the file is open because in my parsing cpp file, i changed dfa_file.fail() to !dfa_file.is_open() and it stopped giving me that error. so what am i doing wrong?
EDIT: I was able to fix the problem by putting the file's full path in variable filename. so like in my main.cpp file i have
std::string filename = "/Users/myname/Documents/DFA/no000.dfa";
fail()and the! is_open()?