以下代码导致运行时错误。在给定的代码中,'blocked' 和 'passed' 是两个字符串向量,长度分别为 bl 和 pl。'low' 是字符串向量的迭代器。
int pos;
vector<string> f;
vector<string>::iterator low;
for(int i=0;i<bl;i++) {
string x=blocked[i];
low=lower_bound(passed.begin(),passed.end(),x); //lower_bound function is used on the vector 'passed'.
index=low-passed.begin(); //finding the index of the string in the vector 'passed'.
string y=passed[index];
int xlen=x.length();
int ylen=y.length();
int minlen=min(xlen,ylen);
for(int i=0;i<minlen;i++) {
if(x[i]!=y[i]) {
pos=i;
break;
}
}
string h=x.substr(0,pos+1);
f.push_back(h);
}
int d=f.size();
for(int i=0;i<f.size();i++) {
cout<<f[i]<<endl;
}
上述代码的完整代码位于https://ideone.com/4NgCWz。请帮忙!