Dudearoo
Useing Code::Blocks
How do i Parse??? Can you guys Teach me how to parse a Config File? i Do have the Boost Librarys Installed so if any of you have a way to do Parsing with it then thats ok, I will be able to Follow :)

Here is The Config File Named Settings
Settings.Config---------------------------------------------

TXTFont=16px
BKCLR=Black
Username=Dudearoo
// As A Comment

Settings.Config-----------------------------------------End

I want to Be able To Parse This Config File and load its values to strings, For Example
TXTFont(String) -> Text_DIVFontSize(String)
I've been useing File I/O For Quit a long time Now, and i still do not Know how to Parse! Please Help you guys :)

Ps. Oh by the way Please Dont send me of on some link so i can figure out how to do this on some other site, i want to you guys to teach me how(But of course Refrences IF Needed). :)

Well I know you want someone here to teach you but I dont see the point if there are perfectly good lessons somewhere else. http://www.cplusplus.com/faq/sequences/strings/split/ has a very good tutorial on how to accomplish what you need. I would suggest try using what is there and see what you come up with. If youy still need help post the code you have, any errors you are getting and/or what it should be doing and what it is not doing and you should get some help.

Look at the patterns. Each parameter in the config file has an '=' sign in it. The part before the '=' is the parameter, and the part after is the parameter value. So, do this.

  1. Read line into buffer.
  2. Check for comment character ('#')
  3. if no comment, look for '=' using strchr(buffer, '=')
  4. if return value from strchr is not null, you now know you have a parameter + value.

I leave the bit about extracting the parameter+value up to you. I only help with school problems - I don't solve them for you!

Um, first ill go to rubberman, i want my buffer to be a String(Sorry I should have said something :)) so i dont have to worry about the possable Character Length, possabley if you can show me a diffrent way for 3.? The other two i've got(Comment Read).
Second, NathanOliver Maybe if you could Explain In more Detail the way of the "Split The String", and Why i need to know this.

Plus: This IS NOT for Any Schooling of any type, I've tought my self All i know About C++.
Just if you were wondering :)

Look up the methods in the string class. The methods for searching, splitting, and all that stuff are well documented.

Can you tell me more detailed places to go? The Answers are great in all but i just want to know WHY I NEED TO KNOW this. :)

Can somebody Tell me another Way then strchr, Due to useing Chars, NOT C++ String, i cant use them for what i want. Thanks,

Since you mentioned Boost, have you looked at Boost program_options? It has a nice syntax for parseing these kind of files. Lots of the tutorials on the site are about using it to parse command line arguments, but the is a section about parsing config file here.

The only thing that I think could be an issue is that you specified that // was to be used for comments, but program_options uses # by default. I don't know if that's configurable though.

Have fun

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.