C++ - run time error- HELP
Hi, I've some problem with a program that I'm trying to write. I'm trying to write a simple file parserwith receive input file and output file , create an object of the parser and call it's parse function. The problme is that in the end of the problem, when I'm tring to return0 in the main, I receive the following error: "Unhandled exception in parse__utility.exe: 0xC0000005: Access Violation" I guess that there is a problem with the destructor but I can find what's worng. I attached the relevantcode: hope someone can help me. ===================================================== Main.cpp --------- #include <fstream> #include <iostream> #include "Parser.h" const int ERR = 1; const int OK = 0; int main(int argc, char *argv[]){ if (argc != 3){ std::cerr << "Wring usage\n"; return ERR; } std::ifstream fin; std:
fstream fout; fin.open(argv[1]); fout.open(argv[2]); if (!fin.good()){ std::cerr << "Bad input file " << argv[1] << "\n"; return ERR; } if (!fout.good()){ std::cerr << "Bad output file " << argv[2] << "\n"; return ERR; } Parser fileParser(fin, fout); fileParser.parse(); fin.close(); fout.close(); return OK; <=== The abend occurs here } ===================================================== Parser.cpp ----------- #include <fstream> #include <iostream> #include "Parser.h" Parser:
arser(std::ifstream& fin, std:
fstream& fout) : m_fin(fin), m_fout(fout) { m_buf = new std::string[10]; } Parser::~Parser() { delete[] m_outputbuf; m_buf = 0; } void Parser:
arse() { m_buf[0] = "ffffffffffffffff"; } ============================================= Parser.h ---------- #include <fstream> class Parser { public: Parser(std::ifstream& fin, std:
fstream& fout); ~Parser(); void parse(); private: std::ifstream m_fin; std:
fstream m_fout; std::string* m_buf; }; ============================================== Regards, Monshu
Hi, I've some problem with a program that I'm trying to write. I'm trying to write a simple file parserwith receive input file and output file , create an object of the parser and call it's parse function. The problme is that in the end of the problem, when I'm tring to return0 in the main, I receive the following error: "Unhandled exception in parse__utility.exe: 0xC0000005: Access Violation" I guess that there is a problem with the destructor but I can find what's worng. I attached the relevantcode: hope someone can help me. ===================================================== Main.cpp --------- #include <fstream> #include <iostream> #include "Parser.h" const int ERR = 1; const int OK = 0; int main(int argc, char *argv[]){ if (argc != 3){ std::cerr << "Wring usage\n"; return ERR; } std::ifstream fin; std: