vendredi 31 mai 2019

C++ substring searching - JUMPING INTO C++

I'm reading "Jumping Into C++" by Alex Allain. I'm at a chapter on strings and searching strings, and I don't really understand this for-loop. Someone please explain to me how this works. Thanks.

for ( i = input.find( "cat", 0 ); i != string::npos; i = input.find( "cat", i ) )
{
    cat_appearances++;
    i++; // Move past the last discovered instance to avoid
    // finding same string again
}
    cout << "The word cat appears " << cat_appearances << " in the string
    " << '"' << input << '"';
}

Aucun commentaire:

Enregistrer un commentaire