c++ - Unhandled exception: Access violation reading location 0x00474EB4 -
i complete beginner in c++, , asked things way more difficult have learned.
i trying read information binary file, (infofile.dat) , display on console.
the program reading info , displaying on console no problem, , can continue using program normally.
however, after exit program using: return exit_success window appears , error shows:
unhandled exception @ 0x542fccc8 (msvcp110d.dll) in pcp.exe: 0xc0000005: access violation reading location 0x00474eb4. the error shows when try reading file, not writing. , when exit program using return exit_success or exit(1) (not when close console window x button)
please know have googled, looked @ many question in stackoverflow same error, none of them helped
code:
display function:
driverobj object of class driver
void staff::displaydriver(){ int i=1; ifstream fp1; fp1.open("infofile.dat",ios::binary); if(fp1.is_open()){ while(!fp1.eof()) { fp1.read((char*)&driverobj,(sizeof(driverobj))); cout << << ". "; driverobj.showdriver(); i++; } } else{ cout << "file not found!" << endl; } fp1.close(); } show function
void driver::showdriver(){ cout << "id: " << id << " - name: " << name << " - zipcode: " << zipcode << " - phone: " << phone << endl; } driver class
class driver : public user { protected: string name; long phone; int id, zipcode; vehicle vehicle; public: driver(); driver(int,string,int ,long , vehicle); void showdriver(); int getid(); }; also, visual studio shows me in "xutility" after breaks:
*_pnext != 0; *_pnext = (*_pnext)->_mynextiter) (*_pnext)->_myproxy = 0;
Comments
Post a Comment