Checks if the given character is an alphabetic character as classified by the currently installed C locale. In the default locale, the following characters are alphabetic:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
In locales other than "C", an alphabetic character is a character for which std::isupper() or std::islower() returns non-zero or any other character considered alphabetic by the locale. In any case, std::iscntrl(), std::isdigit(), std::ispunct() and std::isspace() will return zero for this character.
The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
[edit] Parameters ch - character to classify [edit] Return valueNon-zero value if the character is an alphabetic character, zero otherwise.
[edit] NotesLike all other functions from <cctype>, the behavior of std::isalpha
is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:
bool my_isalpha(char ch) { return std::isalpha(static_cast<unsigned char>(ch)); }
Similarly, they should not be directly used with standard algorithms when the iterator's value type is char or signed char. Instead, convert the value to unsigned char first:
int count_alphas(const std::string& s) { return std::count_if(s.begin(), s.end(), // static_cast<int(*)(int)>(std::isalpha) // wrong // [](int c){ return std::isalpha(c); } // wrong // [](char c){ return std::isalpha(c); } // wrong [](unsigned char c){ return std::isalpha(c); } // correct ); }[edit] Example
Demonstrates the use of std::isalpha
with different locales (OS-specific).
#include <cctype> #include <clocale> #include <iostream> int main() { unsigned char c = '\xdf'; // German letter à in ISO-8859-1 std::cout << "isalpha(\'\\xdf\', default C locale) returned " << std::boolalpha << !!std::isalpha(c) << '\n'; std::setlocale(LC_ALL, "de_DE.iso88591"); std::cout << "isalpha(\'\\xdf\', ISO-8859-1 locale) returned " << static_cast<bool>(std::isalpha(c)) << '\n'; }
Possible output:
isalpha('\xdf', default C locale) returned false isalpha('\xdf', ISO-8859-1 locale) returned true[edit] See also ASCII values characters
isalpha
iswalpha
\x0
â\x8
\0
â\10
control codes (NUL
, etc.) â 0
0
0
0
0
0
0
0
0
0
0
0
9 \x9
\11
tab (\t
) â 0
0
â 0
â 0
0
0
0
0
0
0
0
0
10â13 \xA
â\xD
\12
â\15
whitespaces (\n
, \v
, \f
, \r
) â 0
0
â 0
0
0
0
0
0
0
0
0
0
14â31 \xE
â\x1F
\16
â\37
control codes â 0
0
0
0
0
0
0
0
0
0
0
0
32 \x20
\40
space 0
â 0
â 0
â 0
0
0
0
0
0
0
0
0
33â47 \x21
â\x2F
\41
â\57
!"#$%&'()*+,-./
0
â 0
0
0
â 0
â 0
0
0
0
0
0
0
48â57 \x30
â\x39
\60
â\71
0123456789
0
â 0
0
0
â 0
0
â 0
0
0
0
â 0
â 0
58â64 \x3A
â\x40
\72
â\100
:;<=>?@
0
â 0
0
0
â 0
â 0
0
0
0
0
0
0
65â70 \x41
â\x46
\101
â\106
ABCDEF
0
â 0
0
0
â 0
0
â 0
â 0
â 0
0
0
â 0
71â90 \x47
â\x5A
\107
â\132
GHIJKLMNOP
QRSTUVWXYZ
0
â 0
0
0
â 0
0
â 0
â 0
â 0
0
0
0
91â96 \x5B
â\x60
\133
â\140
[\]^_`
0
â 0
0
0
â 0
â 0
0
0
0
0
0
0
97â102 \x61
â\x66
\141
â\146
abcdef
0
â 0
0
0
â 0
0
â 0
â 0
0
â 0
0
â 0
103â122 \x67
â\x7A
\147
â\172
ghijklmnop
qrstuvwxyz
0
â 0
0
0
â 0
0
â 0
â 0
0
â 0
0
0
123â126 \x7B
â\x7E
\172
â\176
{|}~
0
â 0
0
0
â 0
â 0
0
0
0
0
0
0
127 \x7F
\177
backspace character (DEL
) â 0
0
0
0
0
0
0
0
0
0
0
0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4