I am trying to make a program that will check the remaining number of an item left in stock and that will, if someone buys it, subtract the amount of the item bought and then re-write it into the database... (Something like what they use in some stores)

How do I do this?

depends on how the file is written. If its a simple text file then you will most likely have to completly rewrite the file.

EG:

Name:bag of rice; Price:$49.32; Amount:445

Yup, rewrite the entire file , replacing the line you need to change.

Load each line in a string, check if it matches a certain token, update it, than write it to a file.
I would suggest using two files, the original, from which you will read, and the other on which you make updates:
You read the original file, line by line, if the line doesn't meet the criteria, you write it into the new file. If it doest meet the criteria, you updated that string, than write it to the file, than copy the rest of the file.
Links:
To get a whole line (even from a file): getline
Used for tokenize: stringstream
Also try to work dynamically, creating the name of the new file from the name of the original, so that it will be easy to spot.
Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.