std::isalpha(3)
๐ธ std::isalpha(3) โ C++ Standard Libary ๐ธ
okay bestie, welcome to the std::isalpha(3) page, straight from the C++ Standard Libary (yes, thatโs the spelling on the page, and weโre keeping it ๐
). This is the alphabet-checking icon of <cctype>, and weโre gonna get through every flag, every caveat, and the entire chaotic ASCII table without losing a single crumb. ๐
๐ NAME ๐
std::isalpha - std::isalpha
(no cap, the NAME section is literally the name twice. main character energy.)
โจ Synopsis โจ
Defined in header <cctype>:
int isalpha( int ch );
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:
- uppercase letters
ABCDEFGHIJKLMNOPQRSTUVWXYZ - lowercase letters
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 ofchis not representable asunsigned charand is not equal toEOF. Like, literally undefined โ do not play with that. ๐ญ
๐ Parameters ๐
chโ character to classify
๐ Return value ๐
Non-zero value if the character is an alphabetic character, zero otherwise. Thatโs it, thatโs the whole vibe check. โจ
๐ฆ Notes ๐ฆ
Like 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
);
}
๐ Example ๐
Demonstrates the use of std::isalpha with different locales (OS-specific).
// Run this code
#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
๐ See also ๐
isalpha(std::locale)โ checks if a character is classified as alphabetic by a locale (function template)iswalphaโ checks if a wide character is alphabetic (function)- C documentation for
isalpha
๐งฎ ASCII values (the whole entire table) ๐งฎ
Bestie, this table is a lot, but every crumb stays. The original column headings are, in order:
ASCII values, characters, iscntrl, isprint, isspace, isblank, isgraph, ispunct, isalnum, isalpha, isupper, islower, isdigit, isxdigit, decimal, hexadecimal, octal, iswcntrl, iswprint, iswspace, iswblank, iswgraph, iswpunct, iswalnum, iswalpha, iswupper, iswlower, iswdigit, iswxdigit.
Then each row below is the row content exactly as the page gives it, in order โ no crumbs dropped, no values invented. ๐ซถ
0โ8,\x0โ\x8,\0โ\10, control codes (NUL, etc.),โ 0,0,0,0,0,0,0,0,0,0,0,09,\x9,\11, tab (\t),โ 0,0,โ 0,โ 0,0,0,0,0,0,0,0,010โ13,\xAโ\xD,\12โ\15, whitespaces (\n,\v,\f,\r),โ 0,0,โ 0,0,0,0,0,0,0,0,0,014โ31,\xEโ\x1F,\16โ\37, control codes,โ 0,0,0,0,0,0,0,0,0,0,0,032,\x20,\40, space,0,โ 0,โ 0,โ 0,0,0,0,0,0,0,0,033โ47,\x21โ\x2F,\41โ\57,!"#$%&'()*+,-./,0,โ 0,0,0,โ 0,โ 0,0,0,0,0,0,048โ57,\x30โ\x39,\60โ\71,0123456789,0,โ 0,0,0,โ 0,0,โ 0,0,0,0,โ 0,โ 058โ64,\x3Aโ\x40,\72โ\100,:;<=>?@,0,โ 0,0,0,โ 0,โ 0,0,0,0,0,0,065โ70,\x41โ\x46,\101โ\106,ABCDEF,0,โ 0,0,0,โ 0,0,โ 0,โ 0,โ 0,0,0,โ 071โ90,\x47โ\x5A,\107โ\132,GHIJKLMNOPQRSTUVWXYZ,0,โ 0,0,0,โ 0,0,โ 0,โ 0,โ 0,0,0,091โ96,\x5Bโ\x60,\133โ\140, characters:[,\,],^,_,`; flags:0,โ 0,0,0,โ 0,โ 0,0,0,0,0,0,097โ102,\x61โ\x66,\141โ\146,abcdef,0,โ 0,0,0,โ 0,0,โ 0,โ 0,0,โ 0,0,โ 0103โ122,\x67โ\x7A,\147โ\172,ghijklmnopqrstuvwxyz,0,โ 0,0,0,โ 0,0,โ 0,โ 0,0,โ 0,0,0123โ126,\x7Bโ\x7E,\172โ\176,{|}~,0,โ 0,0,0,โ 0,โ 0,0,0,0,0,0,0127,\x7F,\177, backspace character (DEL),โ 0,0,0,0,0,0,0,0,0,0,0,0
xoxo bestie ๐ โ source/version: http://cppreference.com, date 2024.06.10, page std::isalpha(3). periodt. ๐ซถ
๐ฆ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms