Omnet :多维矢量作为输入
Omnet++: multidimensional vector as input
我设法将一个向量从omnetpp.ini用作字符串的输入,并用作Bool,如下所示,
//omnetpp.ini
**.setGate = "true false false false true false false"
//mynetwork.cc
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;
...
};
我在Omnet 手册中没有找到任何使我可以根据以下的多维输入的东西,
//omnetpp.ini
**.setGate = "true false false false true false false,
false false false false false false false,
true false false false true false false"
如何克服这样的问题?
没有简单的方法可以读取多维数组。使用cStringTokenizer
可能是最好的主意。我建议以下代码读取该数组:
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;
}
y++;
}
x++;
}
注意:
您必须事先知道数组的尺寸。
使用许多行在
omnetpp.ini
中编写字符串参数,您应该在每行的末端放置后斜线,但最后一行,例如:**.setGate = "true true false, false false false"
相关文章:
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 2D数组来自文本输入,中间有空格
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 检查输入是否不是整数或数字
- 正在尝试了解输入验证循环
- 读取文件并输入到矢量中
- C++如何通过用户输入删除列表元素
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 用户定义函数中的指针和输入
- 如何在C++中检查2D数组中负值的输入验证
- 如何只允许用户输入正整数
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- Omnet++:为每个输入单独的cQueue
- Omnet :多维矢量作为输入