std::isgraph(3)
β¨ NAME β¨
std::isgraph β bestie, the name is literally just std::isgraph again (the manpage said so and I'm not about to argue with it π). It's the C++ standard library buddy that tells you whether a character is graphic.
π Synopsis π
Ok so first things first: it lives in the header <cctype> π
int isgraph( int ch );
What it does: checks if the given character is graphic (has a graphical representation) as classified by the currently installed C locale. Slay.
In the default C locale, the following characters are graphic:
- digits (
0123456789) - uppercase letters (
ABCDEFGHIJKLMNOPQRSTUVWXYZ) - lowercase letters (
abcdefghijklmnopqrstuvwxyz) - punctuation characters (
!"#$%&'()*+,-./:;<=>?@[\]^_{|}~`)
π¨ Behavior is undefined if the value ofchis not representable asunsigned charand is not equal toEOF. Not a vibe. Do not do that.
π¦ Parameters π¦
chβ the character to classify π
πΈ Return value πΈ
Non-zero value if the character has a graphical representation character, zero otherwise. That's it, that's the whole answer β¨
π Notes π
Like all other functions from <cctype>, the behavior of std::isgraph 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_isgraph(char ch)
{
return std::isgraph(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_graphs(const std::string& s)
{
return std::count_if(s.begin(), s.end(),
// static_cast<int(*)(int)>(std::isgraph) // wrong
// [](int c){ return std::isgraph(c); } // wrong
// [](char c){ return std::isgraph(c); } // wrong
[](unsigned char c){ return std::isgraph(c); } // correct
);
}
Likeβ¦ the static_cast<unsigned char> is the whole personality of this page, ngl π It's giving "cast it or regret it."
π§ Example π§
// Run this code
#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
unsigned char c = '\xb6'; // the character ΒΆ in ISO-8859-1
std::cout << "isgraph(\'\\xb6\', default C locale) returned "
<< std::boolalpha << (bool)std::isgraph(c) << '\n';
std::setlocale(LC_ALL, "en_GB.iso88591");
std::cout << "isgraph(\'\\xb6\', ISO-8859-1 locale) returned "
<< std::boolalpha << (bool)std::isgraph(c) << '\n';
}
π Possible output π
isgraph('\xb6', default C locale) returned false
isgraph('\xb6', ISO-8859-1 locale) returned true
Locale said "not today" then said "ok actually yes" π iconic honestly.
π See also π
isgraph(std::locale)β checks if a character is classified as graphical by a locale (function template)iswgraphβ checks if a wide character is a graphical character (function)- C documentation for
isgraph
β ASCII values β
This is the full classification chart from the original page, with the columns ASCII values, characters, decimal / hexadecimal / octal, then iscntrl isprint isspace isblank isgraph ispunct isalnum isalpha isupper islower isdigit isxdigit, and the wide-character twins iswcntrl iswprint iswspace iswblank iswgraph iswpunct iswalnum iswalpha iswupper iswlower iswdigit iswxdigit. β 0 means non-zero, 0 means zero. Yes bestie, I kept every single row π
ASCII values characters decimal hexadecimal octal description iscntrl isprint isspace isblank isgraph ispunct isalnum isalpha isupper islower isdigit isxdigit iswcntrl iswprint iswspace iswblank iswgraph iswpunct iswalnum iswalpha iswupper iswlower iswdigit iswxdigit
0β8 \x0β\x8 \0β\10 control codes β 0 0 0 0 0 0 0 0 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0 0
(NUL, etc.)
9 \x9 \11 tab (\t) β 0 0 β 0 β 0 0 0 0 0 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0 0
whitespaces
10β13 \xAβ\xD \12β\15 (\n, \v, \f, \r) β 0 0 β 0 0 0 0 0 0 0 0 0 0 β 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 β 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 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 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 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 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 0 β 0 0 0 0 0 0 0 0 0 0 0
71β90 \x47β\x5A \107β\132 GHIJKLMNOP 0 β 0 0 0 β 0 0 β 0 β 0 β 0 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0
QRSTUVWXYZ
91β96 \x5Bβ\x60 \133β\140 [\]^_` 0 β 0 0 0 β 0 β 0 0 0 0 0 0 0 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 0 β 0 0 0 0 0 0 0 0 0 0 0
103β122 \x67β\x7A \147β\172 ghijklmnop 0 β 0 0 0 β 0 0 β 0 β 0 0 β 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0
qrstuvwxyz
123β126 \x7Bβ\x7E \172β\176 {|}~ 0 β 0 0 0 β 0 β 0 0 0 0 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0
127 \x7F \177 backspace β 0 0 0 0 0 0 0 0 0 0 0 0 β 0 0 0 0 0 0 0 0 0 0 0 0
character (DEL)
Anyway bestie, that's the whole page π this was std::isgraph from the C++ Standard Library, straight from http://cppreference.com, dated 2024.06.10, and it's filed as std::isgraph(3). Go cast your chars to unsigned char and stay safe out there π«Άβ¨
π¦ 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