Mour_Ka Mour_Ka - 1 year ago 64
C++ Question

Omnet++: multidimentional vector as input

I managed to have one vector as input from omnetpp.ini as string and to be used as bool as per below,

**.setGate = "true false false false true false false"

bool MyQueue::gateState()
// reading input from omnetpp.ini as string
const char *vstr = par("setGate").stringValue();
std::vector<std::string> v = cStringTokenizer(vstr).asVector();

//Converting String Vector as bool Vector
bool mygate[6];

for (int x = 6; x>=0; x--){
if (v[x] == "true")
mygate[x] = true;
else mygate[x] = false;

I didn't find in Omnet++ manual any thing that allows me to have a multidimensional input as per below,

**.setGate = "true false false false true false false,
false false false false false false false,
true false false false true false false"

Any Ideas how can I overcome such a problem?

Answer Source

There is no a simple way to read a multidimensional array. And using cStringTokenizer in probably the best idea. I propose the following code to read that array:

bool gatesBool[10][10]; // let's assume these dimensions

const char * tableStr = par("setGate").stringValue();
cStringTokenizer table(tableStr, ","); // a comma separates rows
int x = 0;
while (table.hasMoreTokens()) {
    cStringTokenizer row(table.nextToken(), " "); // a space separates elements
    int y = 0;
    while (row.hasMoreTokens()) {
        if (strcmp(row.nextToken(), "true") == 0) {
            gatesBool[x][y] = true;
        } else {
            gatesBool[x][y] = false;


  1. You have to know in advance the dimensions of the array.

  2. To write a string parameter in omnetpp.ini using many lines you should place backslash at the end of each line but the last, for example:

    **.setGate = "true true false,\
                  false false false"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download