vendredi 26 janvier 2018

Reverse For loop Crashes

So I have this code and it crashes xcode

void strrev(const std::string& str)
{
    for(size_t i=str.length();i>=0;i--)
    {
        std::cout << str[i];
    }
}

It works fine if I do i>0 but then the first character does not get printed Any suggestions on what is wrong with i>=0 ?

Aucun commentaire:

Enregistrer un commentaire