我的代码出现“不可取消引用的字符串”错误,该代码几乎是从互联网上的某个地方逐字复制的。该应用程序在发布模式(VS 2010)下完美编译,但在调试模式下不断向我抛出错误。它应该在 * 处拆分字符串并将每个单词保存到一个向量中。有没有人有任何想法?它似乎真的不喜欢比较的 (string::npos != found) 部分。
string newString = "Something*NotCool";
size_t found = newString.find_first_of("+*-/%()");
size_t lastPos = 0;
//while (found != newString.length)
while (string::npos != found || string::npos != lastPos)
{
if (found >= newString.length()) break;
if (found == lastPos)
{
lastPos = found+1;
found = newString.find_first_of("+*-/()", found+1);
}
string temp (newString,lastPos,found);
temp.assign(newString, lastPos, found-lastPos);
strings.push_back(temp);
lastPos = found+1;
found = newString.find_first_of("+*-/()", found + 1);
}
非常感谢您的帮助!!!