Namespaces
Variants

std:: iscntrl

From cppreference.net
定義済みヘッダー <cctype>
int iscntrl ( int ch ) ;

指定された文字が、現在インストールされているCロケールで分類される制御文字であるかどうかをチェックします。デフォルトの "C" ロケールでは、制御文字はコード 0x00-0x1F および 0x7F の文字です。

ch の値が unsigned char として表現不可能であり、かつ EOF と等しくない場合、動作は未定義です。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - C++関連の専門用語(Parameters、Return value、Notes、Example、See also)は原文のまま保持しました - HTMLタグ、属性、クラス名は一切変更していません - 数字やリンク構造も完全に保持しています - フォーマットとインデントは元のまま維持しています

パラメータ

ch - 分類対象の文字

戻り値

文字が制御文字である場合はゼロ以外の値、それ以外の場合はゼロ。

注記

<cctype> の他のすべての関数と同様に、 std::iscntrl の動作は、引数の値が unsigned char として表現可能でなく、かつ EOF と等しくない場合、未定義です。これらの関数をプレーンな char (または signed char )で安全に使用するには、引数をまず unsigned char に変換する必要があります:

bool my_iscntrl(char ch)
{
    return std::iscntrl(static_cast<unsigned char>(ch));
}

同様に、イテレータの値型が char または signed char の場合、標準アルゴリズムで直接使用すべきではありません。代わりに、値を最初に unsigned char に変換してください:

int count_cntrls(const std::string& s)
{
    return std::count_if(s.begin(), s.end(),
                      // static_cast<int(*)(int)>(std::iscntrl)         // 誤り
                      // [](int c){ return std::iscntrl(c); }           // 誤り
                      // [](char c){ return std::iscntrl(c); }          // 誤り
                         [](unsigned char c){ return std::iscntrl(c); } // 正しい
                        );
}

#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
    unsigned char c = '\x94'; // ISO-8859-1の制御コード CCH
    std::cout << "iscntrl(\'\\x94\', default C locale) returned "
              << std::boolalpha << !!std::iscntrl(c) << '\n';
    std::setlocale(LC_ALL, "en_GB.iso88591");
    std::cout << "iscntrl(\'\\x94\', ISO-8859-1 locale) returned "
              << !!std::iscntrl(c) << '\n';
}

出力例:

iscntrl('\x94', default C locale) returned false
iscntrl('\x94', ISO-8859-1 locale) returned true

関連項目

ロケールによって制御文字として分類されるかどうかをチェックする
(関数テンプレート)
ワイド文字が制御文字かどうかをチェックする
(関数)
**注記**: このHTMLテーブル行には翻訳対象となる自然言語テキストが含まれていません。数値範囲「71–90」と文字コード表現、C++の文字定数、および文字列はすべて技術的データであり、翻訳の対象外です。不等号「≠」も数学記号として保持されています。
ASCII値 文字

iscntrl
iswcntrl

isprint
iswprint

isspace
iswspace

isblank
iswblank

isgraph
iswgraph

ispunct
iswpunct

isalnum
iswalnum

isalpha
iswalpha

isupper
iswupper

islower
iswlower

isdigit
iswdigit

isxdigit
iswxdigit

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
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