I implemented a mock, while loop (line 34), to try and display all the records at once, but it instead only displayed the 1st record after each iteration of the loop (in this case 3 times.
void display(fstream& dFile, Items & call)
{
//int recNum;
//cout << "Enter the item's record number to view: ";
//cin >> recNum;
size_t descSize;
// Read the size of the string
dFile.read(reinterpret_cast<char*>(&descSize), sizeof(size_t));
// resize string to the correct size
call.desc.resize(descSize);
// read in the string
dFile.read(&call.desc[0], descSize);
// read the quantity, whole & retail cost.
dFile.read(reinterpret_cast<char*>(&call.quantity), sizeof(call.quantity));
dFile.read(reinterpret_cast<char*>(&call.wholeCost), sizeof(call.wholeCost));
dFile.read(reinterpret_cast<char*>(&call.retailCost), sizeof(call.retailCost));
size_t dateSize;
// Read the size of the string
dFile.read(reinterpret_cast<char*>(&dateSize), sizeof(size_t));
// resize string to the correct size
call.dateAdded.resize(dateSize);
// read in the string
dFile.read(&call.dateAdded[0], dateSize);
//dFile.seekg(recNum * sizeof(call), ios::beg);
//dFile.read(reinterpret_cast<char *>(&call),sizeof(call));
Items show;
int i = 0;
while ( ! dFile . eof() && i < 4 )
{
cout << "Description\t: " << call.desc << endl;
cout << "Quantity\t: " << call.quantity << endl;
cout << "Wholesale cost\t: " << call.wholeCost << endl;
cout << "Retail cost\t: " << call.retailCost << endl;
cout << "Date\t\t: " << call.dateAdded << endl;
i++;
}
dFile.close();
}
I'm wondering for the 2nd and the 3rd records, should I implement different instances with vector, then use a for loop to display them?

New Topic/Question
Reply




MultiQuote



|