I am trying to create a simple configuration file that looks like this
url = http://mysite.com
file = main.exe
true = 0
when the program runs, I would like it to load the configuration settings into the programs variables listed below.
string url, file;
bool true_false;
I have done some research and this link seemed to help (nucleon's post) but I can't seem to get it to work and it is too complicated to understand on my part. Is there a simple way of doing this? I can load the file using ifstream
but that is as far as I can get on my own. Thanks!
How about formatting your configuration as JSON, and using a library like jsoncpp?
e.g.
You can then read it into named variables, or even store it all in a std::map, etc. The latter means you can add options without having to change and recompile your configuration parser.
libconfig is very easy, and what's better, it uses a pseudo json notation for better readability.
Easy to install on Ubuntu:
sudo apt-get install libconfig++8-dev
and link:
-lconfig++
I was looking for something that worked like the python module ConfigParser and found this: https://github.com/jtilly/inih