Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file input output (tricky one)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I hav a file called "data.dat" and I want to be able to find a certain line of text, then move to that line so i can work with it.....how would I search for and move to a certain line of text in a file??
 
Im not an expert but I think you need to tell us if data is written to the file in clear blocks say each line being separated by a return character.

Also do you know the line Number? if so then count the lines
in until you reach the required line or read in the lines until you find what you are looking for.

If its a binary file you may have to read the whole lot into memory.

Regards
Charles Winston
 
the original stirng of some particular length say L1.


read the file in a buffer of L1.
Increment the counter to 1.i-e- first time read.
match the string. if same then k
else repeat the procedure

when the string is matched then use seekg(counter*L1), u'll reach the starting position of the string in the file.

wish u good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top