I've never really worked with configuration files before, but I'm interested in using one as a parameter file for an engineering code I'm writing.
Not being a professional programmer, I've spent two days trying to figure out how to import a simple list or array setting using libconfig and I can't seem to get anywhere. Roughly working from the example here, I'm able to successfully import scalar settings, like
(importtest.cfg)
mynumber = 1;
using a main function like
Config cfg;
// check for I/O and parse errors
try
{
cfg.readFile("importtest.cfg");
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading config file." << std::endl;
return(EXIT_FAILURE);
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << " : line " << pex.getLine() << " - " << pex.getError() << std::endl;
return(EXIT_FAILURE);
}
// look for 'mynumber'
try
{
int number = cfg.lookup("mynumber");
std::cout << "your number is " << number << std::endl;
}
catch(const SettingNotFoundException &nfex)
{
std::cerr << "No 'mynumber' setting in configuration file." << std::endl;
}
I get the expected output
your number is 1
But I am unable to import a simple list setting, such as
mylist = (1,2,3,4);
In a similar way. I've tried a number of solutions (like creating a root setting), but don't really understand any of them.
Any help is much appreciated.