   Need help working through a parsing issue
  what whould be the best way to parse the fallowing file?right now I am trying to use a combination of getline and istringstream//[MAP]{width,height}{amountoflayers}//[Background]{imagename,maskname}{width,height}{x,y}//[Background2]{imagename,maskname}{width,height}{x,y}//[Playerground]<Player>{imagename,maskname}{width,height}{x,y}<enemy1>{imagename,maskname}{width,height}{x,y}<enemy2>{imagename,maskname}{width,height}{x,y}<enemy3>{imagename,maskname}{width,height}{x,y}<NPC1>{imagename,maskname}{width,height}{x,y}<NPC2>{imagename,maskname}{width,height}{x,y}<NPC3>{imagename,maskname}{width,height}{x,y}//[Forground]{imagename,maskname}{width,height}{x,y}How I want this to work when it comes to the token [MAP]I want it to fill out the struct for map with data below itthen go to the next token and do the same thing.I want lines that begin width // or are empty  to be skipped.I am using c/c++   
  Are the tokens like 'width' and 'height' actual tokens, or are they placeholders for the 'real' data? If the latter, can you post an example of what the real file would like?   ;  First you need to parse [tokens]When you encounter a '[', read everything until ']'. That gives you the "type" of what you're going to parse. Then read up to the next '[', that gives you the data to be parsed.Feed that data into an appropriate sub-parser based on the type.I think you get the idea.Also, if you can, change the comment token to be a single char like '#' for example. Having to parse two characters makes it more complicated, maybe for nothing?I find many languages to be far better suited for text parsing than C++ (python, for example) If possible, use another language to convert (or "pre-process") your text file into something more easily readable from a C++ program.(Edit: ... or make use C++ as higher level language by using a libriary as suggested below)[Edited by - janta on April 20, 2009 12:45:04 AM];  I've found Boost.Spirit to be useful. It's not too hard to get going with, especially if you can use the default char* iterators. It's worth looking into, anyway.   ;  Here is the actule file to be parsed.It should make a smiple breakout clone game.once I get it to load then I am going to add collition info into the file//[MAP]//width,height{ 800  ,600}//Number of layers{2}//[Background]{background.bmp,backgroundMask.bmp}{800,600}{0,0}//[Playerground]{blocks.bmp,blocksmask.bmp}//image width and height{50,30}//image x and y and  tile id{84,71,1} {161,83,2}{84,119,3}{157,121,4}//[PLAYER]{paddle.bmp,paddlemask.bmp}//image width and height{100,50}//start x and y no need for tile ID{400,500}//[OBJECT1]{ball.bmp,ballmask.bmp}//width and height{40,40}//start x and y no need for tile ID{440,540};  1) How do you know which objects need a tile ID and which don't?2) When a tile ID is needed, how do you know how big the tiles are?   ;Quote:Original post by Zahlman1) How do you know which objects need a tile ID and which don't?2) When a tile ID is needed, how do you know how big the tiles are?1) I only need tile IDs is when I use a single bitmap with multiple tiles in it2) right now all the tiles are the same size. I have not figured out a way to find collition detection on irregular size tiles   ;Quote:Original post by kingpinzs1) I only need tile IDs is when I use a single bitmap with multiple tiles in itHow do you know which bitmaps have multiple tiles in them?   ;  does any one have good way to do this in just c++?Or does any one know any good tutorails for parsing a text file?[Edited by - kingpinzs on April 26, 2009 12:19:24 PM];  How would I use istringstream for this issue? I can not figure out how to get it to find the [values]then read in everything tell the next [values].Is there a way to do that with istringstream or am I going about it the wrong way.Or should I use something differnt? Like getline or something?   