Link to home
Start Free TrialLog in
Avatar of ChronicRAGE
ChronicRAGE

asked on

File Line Handling

Hi, I am doing some simple file io with filestreams.  Currently I am reading line by line via getline and parsing the line read.  Is there a way that I can choose to jump to a particular line in the file and read it?  The file I am working with is huge (10000+ lines) and it takes a while to call getline on every line in the file.  If I know the line I want to read is there an easier way around this?  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the no. of bytes in a line are fixed and u are aware of that number, then u can use seekg () to position the get pointer to the specific line

Amit
If the number of bytes in each line is variable, then you can create an index table that points to the starting position in the file for each line.
Then when you need a specific line, just look it up in the index table, and do a seekg() to get to the position in the file.

Another alternative is to use map view api functions, that maps the entire file contents to memory.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial