isalpha is a function returns true if the character is alphabetic (a, b, c, d...z, A, B, C, D...Z). To know more-
http://www.cplusplus.com/reference/cctype/isalpha/
First your original string is taken as input and saved in
str. Then I traverse the whole
str string from beginning to end. My target is to find a series of consecutive alphabetic characters. If I find one, I store it in the vector
strings (and this is what we want).
temp is used to hold this consecutive series of alphabetic characters.
occurring is used to indicate whether this type of series is currently occurring inside the main loop.
If the
occurring is false and the current character is alphabetic then we can toggle the mode to say that series of alphabetic character is occurring-
1 2 3 4
|
if(!occurring && isalpha(str[i]))
{
occurring = true;
}
|
Else if the current character is not alphabetic and the
occurring is set to true, then we can say that we've found one of such a string. Then we store
temp and reset it for the next use and we also set
occurring to false (as current character is not alphabetic and our desired string isn't occurring)-
1 2 3 4 5 6 7 8
|
else if(!isalpha(str[i]) && occurring)
{
strings.push_back(temp);
temp = ""; // reset
occurring = false;
}
|
You should understand the rest...