fstream file;
file.open ( "inventory.dat", ios::out | ios :: in | ios::binary );
if (!file) // Validate that the file is openable
{
cout << "Error opening file! Program Terminating..." << endl;
exit(0);
}
do
{
cout << "What item number do you need to update? ";
cin >> i.item_num;
file.seekg( (i.item_num-1)*sizeof(i) , ios::beg );
file.read ( reinterpret_cast<char*>(&i),sizeof(i) );
cin.ignore();
cout << "Enter the description: ";
cin.getline(i.description, 30, '\n');
cout << "Enter quantity on hand: ";
cin >> i.qty_on_hand;
cout << "Enter wholesale price: ";
cin >> i.wholesale;
cout << "Enter retail price: ";
cin >> i.retail;
//write the record to the binary file
file.seekp((i.item_num-1)*sizeof(i) , ios::beg );
file.write(reinterpret_cast<char*>(&i) , sizeof(i));
cout << "Do you want to update another item? ( Y or N ): ";
cin >> input;
input = toupper ( input );
cout << endl << endl;
} while ( input == 'Y' );
file.close();
I've tried numerous things ( adding seekp). It begins to infinite loop right after I enter the description (a string). I am using a break so I have no idea why it is doing this.
Thanks in advance for any advice
Never mind!Got it

New Topic/Question
Reply


MultiQuote


|