我遇到了一件很奇怪的事情。我遇到问题的代码是:
int stringPos;
int found1;
while (stringPos < 1);
{
//start searching inString for framen starting at foundn and record
found1 = inString.find(frame1, found1);
cout << found1 << endl;
//if return is a number, push back foundn to a vector
if (found1 != -1)
{
foundPositions.push_back(found1);
}
//if return is npos, then break the loop
else
{
stringPos=1;
}
//add 1 to foundn so that the search would continue from where the
//search ended last
found1+=1;
}
奇怪的是,当我把它放在cout << found1 << endl;
这条线下面时found1 = inString.find(frame1, found1);
,循环会正确执行。但是,如果我没有cout << found1 << endl;
它,它会进入无限循环......
有什么建议么?谢谢!