I have a character array that I have to completely check. It is necessary to make so that only alphabetic characters are checked, and specials. characters, numbers, spaces and unicode were not checked.
How to do it?
I have a character array that I have to completely check. It is necessary to make so that only alphabetic characters are checked, and specials. characters, numbers, spaces and unicode were not checked.
How to do it?
I also recommend reading the description in English cppreference.
This function will return a non-zero value if the argument is a letter in the current locale, if it is not a letter - returns 0. In the default locale it returns non-zero (true) for the characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .
Example of use:
std::string word; std::cin >> word; for (int i = 0; i < word.size(); ++i) { char x = word[i]; if (std::isalpha((unsigned char)x)) { // some code } } Another way, without using the standard library, but formally it is not guaranteed by the standard (although in practice, most likely, this will happen):
bool isLetter(char x) { return (x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z'); } The latter method is not very good, because the standard does not guarantee that the letters go in order from 'A' to 'Z' (and similarly for lowercase).
std::cin >> str; , then reading is just before the gap. - zcorvidSource: https://ru.stackoverflow.com/questions/926168/
All Articles
c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'- KoVadim