Reading from a file.

Hey everyone,
I'm working on a project where student issues a book.
when withdrawing a book he gives data that contains his name, ID, department name and issue date. and this information is stored in a text file.
Now in return section.
first I have to match user inputs his ID and checks if this ID really exits or not.
if ID is matched he check when user issued that book. after 14 days of the day of issue, he will be fined 1000 rupees on daily basis.

after returned, that record will be deleted from the file.

here is the data I have in my file:

io99  zafar      oop       computerSC        30|3
cs09  pajaro      oop       computerSC        12|12
io90  Habeeb      oop       computerSC        12|12
re89  Hareem      oop       computerSC        12|12
44rr  anam      oop       computerSC        2|3
oo45  Haseeb      oop       computerSC        12|12


Last edited on
To start with your issue date needs a year, otherwise you may borrow a book 10/30 and return it 10/1, which does not make a time traveler.
Alright, ill add year also... But how other things would go?
It seems you need several programs, what do you have so far ?

Hello Hassibayub,

Since you are just getting started and at some point the program will write to a file I would suggest this file format as it makes reading the file easier. The first fields can be read with "inFile >> variable" where "inFile" would be the name you give to your file stream. Then for the name at the end I would use "std::getline(inFile, Name)". This way if the name should grow to contain a space the "getline" would read the whole name.

If you are stuck with this file format this will work.

Another suggestion would be to read the input file into a class or struct and store this into a vector. If you are not familiar with vectors an array will work, but a vector makes it easier to delete a record.

Hope that helps,

Andy
@Handy Andy

Thank you for opening a path for me. I'll study that vector array online and see how it will come handy for me ...

Thank you..
Topic archived. No new replies allowed.