1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
void printFile(fstream &file, string filename, InventoryCost inv[SIZE]) {
Edit it;
size_t code_length, edit_length;
file.open(filename, ios::in | ios::binary);
if (!file) {
cout << "ERROR opening file!\n";
}
file.clear();
file.read(reinterpret_cast<char *>(&it.itID), sizeof(it.itID));
file.read(reinterpret_cast<char *>(code_length), sizeof(code_length));
it.code.resize(code_length);
file.read((char *)it.code.c_str(), code_length);
file.read(reinterpret_cast<char *>(edit_length), sizeof(edit_length));
it.edit.resize(edit_length);
file.read((char *)it.edit.c_str(), edit_length);
while (!file.eof()) {
cout << it.itID << " " << it.code << " " << it.edit << endl;
for (int i = 0; i < SIZE; i++) {
if (inv[i].getID() == it.itID) {
if (it.code == "AI") {
int add = (stoi(it.edit));
inv[i].setQty(add);
}
else if (it.code == "RI") {
int sub = (stoi(it.edit));
inv[i].setQty(sub);
}
else if (it.code == "CW")
inv[i].setWCost(stof(it.edit));
else if (it.code == "CR")
inv[i].setRCost(stof(it.edit));
else if (it.code == "CD")
inv[i].setDesc(it.edit);
else
cout << "Invalid Transaction Code\n";
}
}
file.read(reinterpret_cast<char *>(&it.itID), sizeof(it.itID));
file.read(reinterpret_cast<char *>(code_length), sizeof(code_length));
it.code.resize(code_length);
file.read((char *)it.code.c_str(), code_length);
file.read(reinterpret_cast<char *>(edit_length), sizeof(edit_length));
it.edit.resize(edit_length);
file.read((char *)it.edit.c_str(), edit_length);
}
file.close();
}
|