Does using the erase function in a string invalidate iterators
问题 I have the following code that takes a string and erases non alphabet characters void removeNonAlpha(string& str){ for (string::iterator it = str.begin(); it < str.end(); it++){ if (!(isUpperCaseLetter(*it) || isLowerCaseLetter(*it) || str == ' ')) str.erase(it--); } } I showed this to my professor and he told me that doing this is risky because it may invalidate the iterator that I'm using. However, I thought that erase will only invalidate iterators after the point of the erase, and I made