i have a problem and i think the solution might be pretty easy but im kinda stuck. I have some kind of config file wich im trying to parse in c++ to get some important values.
It looks like this:
info size=32 bold=0 italic=0 unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0
common lineHeight=32 base=27 scaleW=1024 scaleH=28 pages=1 packed=0 alphaChnl=1
chars count=74
char id=32 x=837 y=15 width=3 height=1 xoffset=-1 yoffset=31 xadvance=8 page=0 chnl=15
char id=33 x=802 y=0 width=4 height=19 xoffset=2 yoffset=8 xadvance=8 page=0 chnl=15
char id=35 x=292 y=0 width=17 height=19 xoffset=0 yoffset=8 xadvance=16 page=0 chnl=15
char id=37 x=177 y=0 width=19 height=19 xoffset=-1 yoffset=8 xadvance=17 page=0
chnl=15
char id=38 x=216 y=0 width=18 height=19 xoffset=0 yoffset=8 xadvance=18 page=0 chnl=15
Info, common and chars a basic/global values. Every char line should be saved in an array (or vector) of structs with a similar format (x, y, height, offsetX, offsetY …)
Now i’ve tried getline() for example to get every line one by one and then make an istringstream with these lines to “search” those lines for the values i need.
Its worth noticing that iam not needing all those values i need a way to just save the one i need for every line.
Thanks in advance for any help here!
Each line is prefixed by the type of object.
So your reader should read the first word off and then decide what object to read.
For each type of object you need to define a structure to hold the data.
Now you have to define a method to read the data. In C++ we use
operator>>to read data from a stream.Repeat the processes for the other types you need to read. Then writting the read commands becomes simple:
Repeat the processes for the other types.