c++ - Segmentation fault (core dumped) error occurred -
i keep getting segmentation fault (core dumped) error. program runs fine first line of code though, don't know why messes on second line. line of code causes problem xxml->setelementdata(selementname, scontent) one. or direction of problem appreciated!
#incude <iostream> void parseelement(istream & input, string sprefix, vector<xmlserializable*> & vvector, map<string, function<xmlserializable*()>>& mmap) { xmlserializable * xxml; string selementname; getline(input, selementname, '>'); if( selementname.back() == '/' ) { cout << sprefix << "empty element: " << selementname << endl; return; } else { cout << sprefix << "element - " << selementname << endl; if (selementname == "item") { function<xmlserializable*()> pfuncitem = mmap["item"]; xxml = pfuncitem(); vvector.push_back(xxml); } if (selementname == "weapon") { function<xmlserializable*()> pfuncweapon = mmap["weapon"]; xxml = pfuncweapon(); vvector.push_back(xxml); } if (selementname == "armor") { function<xmlserializable*()> pfuncarmor = mmap["armor"]; xxml = pfuncarmor(); vvector.push_back(xxml); } if (selementname == "creature") { function<xmlserializable*()> pfunccreature = mmap["creature"]; xxml = pfunccreature(); vvector.push_back(xxml); } } string scontent = ""; while( true ) { char c = input.get(); while( c != '<' ) { if( c != '\n' ) scontent.push_back(c); c = input.get(); } if( input.peek() == '/' ) { input.get(); string sendelement; getline(input, sendelement, '>'); if( sendelement != selementname ) cout << "bad xml found" << endl; cout << sprefix << "content - " << scontent << endl; xxml ->setelementdata(selementname, scontent); return; } else { parseelement(input, sprefix + " ", vvector, mmap); } } }
Comments
Post a Comment