std:: isgraph
|
定義済みヘッダー
<cctype>
|
||
|
int
isgraph
(
int
ch
)
;
|
||
指定された文字がグラフィック(図形的表現を持つ)であるかどうかを、現在インストールされているCロケールで分類された基準でチェックします。デフォルトのCロケールでは、以下の文字がグラフィックと見なされます:
-
数字 (
0123456789) -
大文字アルファベット (
ABCDEFGHIJKLMNOPQRSTUVWXYZ) -
小文字アルファベット (
abcdefghijklmnopqrstuvwxyz) -
句読点文字 (
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)
ch の値が unsigned char として表現不可能であり、かつ EOF と等しくない場合、動作は未定義です。
目次 |
パラメータ
| ch | - | 分類対象の文字 |
戻り値
文字が図形的な表現を持つ場合は非ゼロ値、それ以外の場合はゼロ。
注記
<cctype>
の他のすべての関数と同様に、
std::isgraph
の動作は、引数の値が
unsigned
char
として表現可能でなく、かつ
EOF
と等しくない場合、未定義です。これらの関数をプレーンな
char
(または
signed
char
)で安全に使用するには、引数をまず
unsigned
char
に変換する必要があります:
bool my_isgraph(char ch) { return std::isgraph(static_cast<unsigned char>(ch)); }
同様に、イテレータの値型が char または signed char の場合、標準アルゴリズムで直接使用すべきではありません。代わりに、値を最初に unsigned char に変換してください:
int count_graphs(const std::string& s) { return std::count_if(s.begin(), s.end(), // static_cast<int(*)(int)>(std::isgraph) // 誤り // [](int c){ return std::isgraph(c); } // 誤り // [](char c){ return std::isgraph(c); } // 誤り [](unsigned char c){ return std::isgraph(c); } // 正しい ); }
例
#include <cctype> #include <clocale> #include <iostream> int main() { unsigned char c = '\xb6'; // ISO-8859-1における文字 ¶ std::cout << "isgraph(\'\\xb6\', default C locale) returned " << std::boolalpha << (std::isgraph(c) != 0) << '\n'; std::setlocale(LC_ALL, "en_GB.iso88591"); std::cout << "isgraph(\'\\xb6\', ISO-8859-1 locale) returned " << std::boolalpha << (std::isgraph(c) != 0) << '\n'; }
出力例:
isgraph('\xb6', default C locale) returned false
isgraph('\xb6', ISO-8859-1 locale) returned true
関連項目
|
ロケールによって図形文字として分類されるかどうかをチェックする
(関数テンプレート) |
|
|
ワイド文字が図形文字かどうかをチェックする
(関数) |
|
|
C documentation
for
isgraph
|
|
| ASCII値 | 文字 |
isgraph
|
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 10進数 | 16進数 | 8進数 | ||||||||||||||
| 0–8 |
\x0
–
\x8
|
\0
–
\10
|
制御コード (
NUL
など)
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
|
| 9 |
\x9
|
\11
|
タブ文字 (
\t
)
|
≠0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
|
| 10–13 |
\xA
–
\xD
|
\12
–
\15
|
空白文字 (
\n
,
\v
,
\f
,
\r
)
|
≠0
|
0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
|
| 14–31 |
\xE
–
\x1F
|
\16
–
\37
|
制御コード |
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 32 |
\x20
|
\40
|
スペース |
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
|
バックスペース文字 (
DEL
)
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
|