我遇到了一些非常奇怪的事情。我有麻煩的代碼是:如果cout丟失,循環進入無限循環
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;
它會進入無限循環...
有什麼建議嗎?謝謝!
該代碼不會做你聲稱它做的。如果您不會向我們顯示問題的代碼,我們如何解決這個問題? –
請閱讀並思考http://sscce.org/ –