dimanche 30 avril 2017

I don't understand why I am recieving an error with string.replace

I do not understand what I am doing wrong here in this function. I am pretty sure I am using the parameters correctly. Is there a #include file I missed?

int countTemplate(const string& str)
{
int count = 0;
while (!str.empty())
{

    size_t beginningTemp;
    size_t endTemp;
    string foundTemp;

    beginningTemp = str.find('@');
    endTemp = str.find('@', beginningTemp+1);
    foundTemp = str.substr(beginningTemp, (endTemp + 1) - beginningTemp);
    count++;
    str.replace(str.find('@'), (endTemp + 1) - beginningTemp, "");
}

return count;
}

Aucun commentaire:

Enregistrer un commentaire