I was trying a function that read an string (which previously had
attached two special characters & for the beginning of the word and #
for the end of the word) and if it was "<word>ize" it changed into
"change into <word>". I did this function:
bool Ize(string& s)
{
bool is=false;
string eval="ize";
int end=s.find('#');
int idx=s.rfind(eval,fin);
if(idx==end-eval.size())
{
is=true;
s.erase(idx,eval.size());
s.insert(s.find('&'),"change into ");
}
return is;
}
The problem I'm running into is with the string "z". For whatever the
reason s.rfind(eval,fin) returns -1 so it enters the if and when I try
to erase all hell breaks lose.
Why does it return -1 and not string::npos?
Thanks.