-
strings
say you have 3 rows of text in a file but you only want to extract
say the second line of text. is there a way to do this and is the a way to store different groups of text and then extract them later using some sort of search method?????????????????
and yes i have searched all day and havn't found anything so if anyone knows a way pleasse tell me........
-
-
seekg() is not going to help with text files unless you already know the exact position of the start of the string, and that's not very likely to be the case with most text files where each line is a different length.
wart101: the only way to extract a specific line is to read the whole file one line at a time, counting the lines as they are read. Just put getline() in a loop and you wil get what you want.
-
Hmm... I though seekg() had a method to specify the start of lines. My apologies.
-
You could just read in the file and save the lines you want to a vector by using push_back(...). Or you could store the whole file (vector) and just keep a record of what lines (indexes) in the file you want.