+ 1

How to use information stored in file as variables in program? and how to randomly access some information in file in c++ ?

I've stored the date of costumer's arrival and when will he left in file ..now i want to calculate his bill using these dates ..how can I?

18th May 2018, 10:43 AM
Maleeha Khalid
Maleeha Khalid  - avatar
7 Réponses
+ 5
There are Sololearn C++ lessons on file manipulation.
18th May 2018, 10:56 AM
Maxwell Anderson
Maxwell Anderson - avatar
+ 2
Go through these lessons: https://www.sololearn.com/learn/CPlusPlus/1920/?ref=app The getline function reads the file line by line and can be used to return a string of a line in the file to either stdout, a variable, a file, etc.
27th May 2018, 12:29 PM
Maxwell Anderson
Maxwell Anderson - avatar
+ 2
Maleeha What more do you need?
27th May 2018, 8:56 PM
Maxwell Anderson
Maxwell Anderson - avatar
+ 2
Maleeha Basically, you will have to loop through all lines in the file and save them to some form of data container that you can then access a line by an index to the container. Or, you can loop through all lines in the file until a desired number of lines is reached and then store that specific line.
28th May 2018, 1:40 AM
Maxwell Anderson
Maxwell Anderson - avatar
0
Maxwell Anderson I've searched the whole course on file handling but couldn't find what I'm looking for..can you share a link?
26th May 2018, 8:43 PM
Maleeha Khalid
Maleeha Khalid  - avatar
0
this is basic..i've learnt it but my problem is still not resolved i.e how to access data in file ..Maxwell Anderson
27th May 2018, 1:03 PM
Maleeha Khalid
Maleeha Khalid  - avatar
0
I'm saving data of guests in file and after checkout their data has to be removed and file is to be updated ..if the data of 2 guest is from line 7 to line 10 ,how will I access it without having to read file from the start and how will it end before end of file ? Maxwell Anderson
27th May 2018, 10:40 PM
Maleeha Khalid
Maleeha Khalid  - avatar