Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

How do you search inside a text file

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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

Share this post


Link to post
Share on other sites
A bit more detail would be helpful. Does that stand alone on it's own line? Is it embedded in some text?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:


read first part of file
loop 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!