【发布时间】:2013-05-31 08:06:55
【问题描述】:
我遇到了一件很奇怪的事情。我遇到问题的代码是:
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; 它会进入无限循环...
有什么建议吗?谢谢!
【问题讨论】:
-
该代码并没有像您声称的那样做。如果您不向我们展示有问题的代码,我们该如何解决?
-
请阅读并思考sscce.org
标签: c++ string while-loop infinite-loop endl