I have a text file containing a number of records. Each record is stored on a single line that is 100 characters long.
Let's say I want to directly access the nth record. I could do it using a for loop, reading in n lines until I get to the record.
But how could I access it directly?
you can make use the the seekg function:
If the each line is exactly 100 characters long and the line ending is always
\n
(i.e. no\r\n
stuff) and there's no blank lines and people won't use 1 tab for 8 spaces etc. you can use (with ifstream)or (with FILE*)
If you are unsure of any of the preconditions, use a loop.