Loading data from a text file.
Posted: Fri Jun 22, 2007 12:43 pm
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.
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.