Any way to load and parse a .cfg file?

I’m trying to load in data from a config (cfg) file and parse it into a custom data struct.
I know how to do this with json and xml formats but was wondering if there’s an addon or built-in support for loading this file format to oF ?


assuming it is in this sort of format:


You could use do something like this.

//get an ofBuffer from the file
ofBuffer buffer = ofBufferFromFile("myFile.cfg");

//for each line in the file

for( auto line : buffer.getLines()){

    //turn the line of text into an array/vector of two or more elements split by the = symbol
    auto arr = ofSplitString(line, "=");
    //for a line like
    if( arr.size() >= 2 ){
        //var would be FILES
        //value would be 30 ( as a string )
        string var = arr[0];
        string value = arr[1];
        cout << " var is " << var << " value is " << value << endl;

Thanks @theo I may have to write my own parser as you suggest, or include a 3rd party lib.
The file format is similar to .ini and contains nodes such as

[cluster_node] id=“n1” addr=“”
[cluster_node] id=“n2” addr=“”


In fact what I want to do is load in a .cfg file and extract all elements with the [cluster_node] label and then get the IP address from each. I can do it easy enough with a few lines of code it’s just that I read here that someone thought it was included in the ofxXmlSettings addon (though I couldn’t even load a .cfg file using that addon) so I thought I would check if there was a lib / addon already.