I am getting a “string not dereferencable” error for my code, which is pretty much copied verbatim from somewhere on the internet. The application compiles perfectly in release mode (VS 2010), however keeps throwing me an error in Debug mode. It should be splitting the string at the * and saving each of the words to a vector. Does anyone have any ideas? It really doesn’t seem to like the (string::npos != found) part of the comparison.
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);
}
Your help is gratefully appreciated!!!
Your code didn’t produce any errors for me in VS2010.
Since you’ve got access to regular expressions (
<regex>library), another alternative could be: