我的程序崩溃了,这对我来说似乎很好,当然我的程序另有说明,这让我感到困惑。
我目前正在处理的这个函数片段:
for(int k = 0; k < dictionary[k].size(); k++)
{
//"i" represents the fragment's first character
//while "k" represents the dictionary first character
if(fragments[i][j] == dictionary[k][j]) {
token++;
cout << token << endl;
}
}
可能是问题所在。当我调试问题时,调试器会转到代码段的第一行:
for(int k = 0; k < dictionary[k].size(); k++)
然后当我尝试进入下一个时崩溃。在调试器中,此窗口在我的代码块中打开:
Signal Received
Program Received Singal SIGEGV, segmentation fault. Do you want to view backtrace?
我点击是,这对我来说似乎是任意的。
有谁知道我做错了什么?
如果需要回溯(窗口显示调用堆栈),如果需要,我稍后会对其进行编辑
编辑:这是整个功能,我认为没有必要
void Language::compare()
{
int para = getParameters(0); //eg. 3
int valid = para;
int token = 0;
for(int i = 0; i < para; i++)
{
//If the string is creater than 2 characters
if(fragments[i].length() > 1) {
for(int j = 0; j < fragments[i].length(); j++)
{
//Checking if that character match in dictionary
for(int k = 0; k < para; k++) //Changed and now works,
{
//"i" represents the fragment's first character
//while "k" represents the dictionary first character
if(fragments[i][j] == dictionary[k][j]) { //But now this line crashes
token++;
cout << token << endl;
}
}
if(token == 0) {
break;
}
}
}
else {
//...
}
}
}
字典和片段在类“语言”中声明,它们都是向量。