Wednesday, March 7, 2012

Reading Configuration Files in C++

This is a quick code snippet to read a user defined configuration files in C++. I use boost libraries.

There many ways to read it(depends on how you have your configuration file written). You can also use  boost::property_tree which can efficiently parse formats such as XML, INI, etc.

Make sure you've installed boost before trying this out.

For a text file with data in the following format(data in each line separated by tab spaces and new unit of data in each line):

The returned data is in form of vector of vectors. You can replace above configuration file with similar structure (and replace tabs with any common delimiter and it will work).

No comments:

Post a Comment