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?

4 Years
Discussion Span
Last Post by Lucaci Andrew

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.
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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.