#include <iostream>
#include <fstream>
using namespace std;
struct inventory {
char item[20];
int quantity;
double cost;
};
int main()
{
ifstream fin("InvDat.dat", ios::in | ios::binary);
if(!fin) {
cout << "Cannot open file.\n";
return 1;
}
inventory inv[3];
for(int i=0; i<3; i++)
fin.read((char *) &inv[i], sizeof(inventory));
fin.close();
if(!fin.good()) {
cout << "A file error occurred.\n";
return 1;
}
for(int i=0; i < 3; i++) {
cout << inv[i].item << "\n";
cout << " Quantity on hand: " << inv[i].quantity;
cout << "\n Cost: " << inv[i].cost << "\n\n";
}
return 0;
}
|