I am using the libconfig c++ library to grab stored data, and need to store that data in a string array in c++ without knowing the number of variables that will be passed through a config file. I know that this isn't really possible in c++, but I am trying to find the best practice to do this, and other solutions don't seem to make practical sense for what I am doing. Below is the portion of the code where I am trying to take the string filetype and store all of the results individually in a string array.
try {
for (int i = 0; i < cfg.getRoot()["files"].getLength(); ++i) {
// Only output the record if all of the expected fields are present.
string filetype;
if (!(cfg.getRoot()["files"][i].lookupValue("filetype", filetype)))
continue;
cout << filetype << endl;
}
}
catch (const SettingNotFoundException &nfex) {
// Ignore.
}
Apologies for the probable facepalm you are having right now, I'm a college student still learning the ropes, and am working well ahead of my course at the moment on a personal project.