tags:

views:

166

answers:

5

Imaging that a program needs to know quite a lot of parameters to do its tasks properly, such as 'Port = 2323' this kind of things.

now I want to save these parameters in a plain text file, similar to Unix' system variables such as users and groups.

Is there any standard way/libraries that can help me to do this? Does anyone ever used them before? thanks

+7  A: 

Boost.Program_options library. Is this you are looking for?

The program_options library allows program developers to obtain program options, that is (name, value) pairs from the user, via conventional methods such as command line and config file.

Kirill V. Lyadvinsky
You could also consider the brand-new (in 1.41) Boost.PropertyTree. It supports reading INI files, if you like that syntax, and some other syntaxes (not to mention you can write your own parsers for it).
John Zwinck
@John, that comment is worth its own answer. Especially if you elaborate
caspin
I actually think Boost.ProgramOptions could be better than PropertyTree: it's more mature, and does support INI file processing (http://www.boost.org/doc/libs/1%5F41%5F0/doc/html/boost/program_options/parse_config_file.html). I figured I'd toss PropertyTree in the mix just because it's a new thing in Boost which might also work, but I'm not comfortable recommending it over ProgramOptions.
John Zwinck
+1  A: 

http://stackoverflow.com/questions/12633/what-is-the-easiest-way-to-parse-an-ini-file-in-c

Sebastian
This should be a comment, not an answer. Besides, the question on your link was about WinAPI. Here question was tagged with `linux` tag.
Kirill V. Lyadvinsky
You're right. A comment would have been appropriate. The linked question included many cross-platform library recommendations though.
Sebastian
A: 

You can also create an alias or shell script that executes your program with given parameters. To conviniently get these parameters there's "getopt"

DaClown
A: 

Link here for a cross platform ini handler. Hope this helps, Best regards, Tom.

tommieb75
+1  A: 

Qt offers this by default, and in a cross-platform way. Checkout out QSettings

Boudewijn Rempt