C++ Flexible Nested Array / Vector Structure

I’m trying to convert an object from P5.js (Javascript) to OpenFrameworks (C++).

The object I made in Javascript contains a combination of strings, a single array of strings or nested arrays of strings (etc), see below:

let array = {
    "string1",
    ["string2","string3"],
    ["string4",["string5","string6"]]
}

I’ve tried making it in C++ using vectors but I keep running into the problem of not having the flexibility for it to hold strings, arrays or arrays within arrays (as my p5.js code can currently parse through unpack these strings as needed).

Thank you for your help in advance! :slight_smile:

Hi @xX_n3c40_Xx ,
just make a custom structure like this:


struct customElement{
std::string s;
int a;
float b;
};

struct CustomArrayStruct {

std::vector < int > vecInt;
std::vector < std::string > vecString;
std::vector < std::vector < std::string > > vecVecString
std::vector < customElement> vecCustom;
//etc...
};

Hope this helps,

Best,

P