I'm currently working on a code for a business, which will track the items it sells and their prices, also keeping a log of all purchases made. The idea I have for the items (and prices) is to have a section of the program that allows you to input an item name and a price, and the computer will generate a random item ID. It will then write all this information into a file, and allow you to view it later. As for the log, it is basically the same thing but in a 'receipt' form.
I read somewhere that the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream itemIDs;
itemIDs.open ("ItemIDs.txt");
if(itemIDs.is_open()) {
itemIDs << newItem;
itemIDs << newPrice;
itemIDs << newID;
myfile.close();
}
return 0;
}
|
will create a new text file names ItemIDs.txt, and input anything I want in it.
That's good, but I don't know how to let the user view it through the program. Also, I have a strong feeling the next time they write something, it will rewrite the file.
BTW, for the receipts, I need to make the names of the files different so they don't mix, and I've done some testing and found out you can't do
Any help? :)