Hi everyone, my first post, but I've been lurking for awhile. I've been using Irrlicht for a few weeks now and have gone through all the tutorials at least once. I'm still fairly new to C++ but I'm picking it up fairly quickly and I have a lot of experience with a few different scripting languages.
I've been experimenting with Irrlicht and I've come to something that I can't figure out how to do. Say I have a text file(.txt) that is split into multiple sections and I have each section labeled with a header and the next line after the header holds a number that tells how many lines are in the section. Much like this:
---
HEADER
numlines 3
0.{data}
1.{data}
2.{data}
SECONDHEADER
numlines 1
0.{data}
---
Now, I know how to read the right number of lines after the 'numlines' string[very basicly: for( i = 0; i < numlines-1; ++i ){}], but what I can't find is how to search through the file for the specific string 'HEADER' using Irrlicht's string system rather than Windows' system. Since the text file will be only a template and not of a static size, I can't just tell the code to look at a specific line number. I'm guessing it has to do with find() in irr::core::string, but that says it's to find a string in another string, so would I have to load the entire file as a string then use something like file.find("HEADER");?
Am I on the right track or is there an easier way to achieve this?
Thanks for any help in advance.
Loading data from a text file.
-
- Posts: 8
- Joined: Sat Jun 16, 2007 6:13 am
- Location: Kansas
-
- Posts: 8
- Joined: Sat Jun 16, 2007 6:13 am
- Location: Kansas
i can provide you with a concept how to parse text files, i have done it several times, several parsers to download data from websites
so the way i would do it is that i would split the file in to an array. each array element holds one line. then i would loop the array and look lets say for header. When header is detected - we do other specific operations to get required data from next array elements (line).
I hope this will help. Too bad i cant provide you with code or something more specific because i have done such thing with php only, no c++ experience in text parsing also if you dont mind using framework, there are a lot of useful functions for string parsing
so the way i would do it is that i would split the file in to an array. each array element holds one line. then i would loop the array and look lets say for header. When header is detected - we do other specific operations to get required data from next array elements (line).
I hope this will help. Too bad i cant provide you with code or something more specific because i have done such thing with php only, no c++ experience in text parsing also if you dont mind using framework, there are a lot of useful functions for string parsing
how to search through the file for the specific string 'HEADER' using Irrlicht's string
Exactly. You firsth load data from file in to string then perform operations on it.I'm guessing it has to do with find() in irr::core::string, but that says it's to find a string in another string, so would I have to load the entire file as a string then use something like file.find("HEADER");?