C++ - run time error- HELP

monshu

New member
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::eek: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::parser(std::ifstream& fin, std::eek:fstream& fout) : m_fin(fin), m_fout(fout) { m_buf = new std::string[10]; } Parser::~Parser() { delete[] m_outputbuf; m_buf = 0; } void Parser::parse() { m_buf[0] = "ffffffffffffffff"; } ============================================= Parser.h ---------- #include <fstream> class Parser { public: Parser(std::ifstream& fin, std::eek:fstream& fout); ~Parser(); void parse(); private: std::ifstream m_fin; std::eek:fstream m_fout; std::string* m_buf; }; ============================================== Regards, Monshu
 

annefan

New member
טוב זה היה נחמד

א. ב-dtor יש טעות (m_outputbuf במקום m_buf) ב. ב-++g יש טעות קומפילציה!! ב-VC6 הקוד שלך עובד ועף כמו שכתבת. מה הטעות? אם אני מבין מה שרצית לעשות, רצית להעביר כ-references את שני ה-streams לתוך המשתנים של המחלקה (m_fin, m_fout). מה שעשית זה לאתחל שני streams חדשים לפי השנים שעוברים כ-references (כנראה ע"י ה-Copy Constructor של ifstream ו-ofstream)!! על מנת לתקן, שנה את m_fin ו-f_out ל-references גם הם. הקוד מתקמפל ורץ בלי בעיות (בהנחה שזה מה שרצית...)
 

annefan

New member
Why do you use English?

Is it a problem of Hebrew Comprehension or (non-)Hebrew copmuter? I mean, do you want the answers in English?
 

monshu

New member
Non Hebrew OS

Yes, I'm writing in english since I have english OS - Win NT4 and I have some difficulties to write in Hebrew...
My company should move to WinXp soon and I can't wait ... - I have NT4 - too many bugs I have no problem to read hebrew... so thank for you help
 
למעלה