Hello,
I am trying to solve an assignment containing file handling.
I am getting error "Memory access violation error".
I know the erroneous statement is "file.read((char*)&p,sizeof(Product))" in Supermarket_Billing_System.cpp line no 103.
Please help me to solve.following are the 2 functions, first one is functioning correctly. While 2nd function is executing whole
get executed correctly and while returning to main body it crashes. If i comment "file.read()" part then
application did not crash.
So what should i do?
void Supermarket_Billing_System::Add_and_WriteNewProduct(Product P) { //Need To Implement ofstream file; file.open("inventory.bin",ios::out|ios::binary|ios::app); file.write((char*)&P,sizeof(Product)); file.close(); } //Read display the product from product list void Supermarket_Billing_System::Read_DisplayProductFromProductList() { //Need To Implement ifstream file; Product p; file.open("inventory.bin",ios::in|ios::binary); while(file.read((char*)&p,sizeof(Product))) //erroneous statement file.read((char*)&p,sizeof(Product))?? p.Display_Product(); file.close(); }
↧
Unhandled exception at 0x77F3CCD2 (msvcp110d.dll) in Supermarket_Billing_System.exe: 0xC0000005: Access violation writing location 0xDDDDDDDD.
↧