How do you search inside a text file
You could load the whole file into a string and then use "find_first_of()"
You could jump from line to line, and assuming the L1: is at the beginning of the line, use "peek()" to look for 'L' and then see if it's "L1:"
You could put everything after L1: into its own file so you don't have to search for it.
Edit: that was really wierd those two posts
You could jump from line to line, and assuming the L1: is at the beginning of the line, use "peek()" to look for 'L' and then see if it's "L1:"
You could put everything after L1: into its own file so you don't have to search for it.
Edit: that was really wierd those two posts
A bit more detail would be helpful. Does that stand alone on it's own line? Is it embedded in some text?
I dont know but that does not sound very afficent because I will need to load a lot of text files and to help keeping the load times low I just wanted to load at a sertin point in the text file.
Thanks For the help
EDIT: it is on a line by it's self then I need all the text below it to be read tell another token/word L2:, L3:, Obj:, NPC: then it keeps going to end of file also I want each text file to be a complete level so I only have to read one text file per level.
Thanks For the help
EDIT: it is on a line by it's self then I need all the text below it to be read tell another token/word L2:, L3:, Obj:, NPC: then it keeps going to end of file also I want each text file to be a complete level so I only have to read one text file per level.
If you don't store the position ahead of time, you're going to have to search everything before it to find "L1:" Then once you have the position use "seekg()" to start reading from that point on.
It sounds like instead of just searching for it, you should just read the file a bit at a time. You probably want the information before it.
This might be off, but it would go like this:
Or you could load the whole file into something like a set with the type (L1, L2, Obj) being the key.
This might be off, but it would go like this:
read first part of fileloop until eof read line switch on line case(L1) .... case(L2) .... case(Obj)....
Or you could load the whole file into something like a set with the type (L1, L2, Obj) being the key.
Boder has the right idea. You just read the file line by line, test the line if it's the string you're looking for ("L1" in your case) and if it is, then you start doing whatever you want to the data that follows.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement