【发布时间】:2015-02-14 01:47:27
【问题描述】:
我已经编写了将字符串解析为称为输入的二维向量的代码。我想将第一个索引的字符串放入一个向量中,该向量存储带有 lhs 和 rhs 的节点。每个向量的第一个索引应该在 lhs 中,每个其他字符都应该在 rhs 中。我的向量下标超出范围,代码循环了 3 次或更多次。我做错了什么?
struct finalNode
{
string rhs;
string lhs;
bool isTerm;
};
void fillGramRules()
{
for (int i = 0; i < input.size(); i++)
{
finalNode fNode;
//attempts to copy first position 0 of every array to string lhs of fnode, this crashes the program
fNode.lhs = input[i][0].symbol;
newNode.isTerm = input[i][0].isTerminal;
for (int j = 1; j < input[i].size()-1; j++)
{
newNode.rhs.append(input[i][j].symbol);
newNode.isTerm = input[i][j].isTerminal;
}
gramRules.push_back(fNode);
}
}
【问题讨论】:
-
显然,
input[[i]对于i的某些值是空的。