Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
int main() {
Book b;
vector<Book> books;
string tempTitle, tempAuthor, tempisbn, tempPrice, tempCost, tempqtyOnHand, tempqtySold;
ofstream out("new_list.txt");
ifstream inClientFile{ "Book_List.txt" };
if (!inClientFile) {
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
while (inClientFile.peek() != EOF) {
//CreateBook to store data, call it b
inClientFile >> quoted(b.title) >> quoted(b.author) >> quoted(tempPrice) >> quoted(tempqtyOnHand) >> quoted(tempqtySold) >> quoted(tempisbn) >> tempCost;
inClientFile.ignore();
b.price = stod(tempPrice);
b.qtyOnHand = stoi(tempqtyOnHand);
b.qtySold = stoi(tempqtySold);
b.cost = stod(tempCost);
out << b.title << ", " << b.author << ", " << b.price << ", " << b.qtyOnHand << ", " << b.qtySold << ", " << b.isbn << ", " << b.cost << ", " << b.calcRevenue(b.price, b.qtySold) << ", " << b.calcProfit(b.price, b.cost, b.qtySold) << endl;
books.push_back(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment