Namespaces
Variants

std:: ispunct

From cppreference.net
ヘッダーで定義 <cctype>
int ispunct ( int ch ) ;

指定された文字が現在のCロケールで分類される句読点文字であるかどうかをチェックします。デフォルトのCロケールでは、文字( !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ )を句読点として分類します。

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

目次

パラメータ

ch - 分類対象の文字

戻り値

文字が句読点文字である場合は非ゼロ値、それ以外の場合はゼロ。

注記

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

bool my_ispunct(char ch)
{
    return std::ispunct(static_cast<unsigned char>(ch));
}

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

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

#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
    unsigned char c = '\xd7'; // ISO-8859-1における文字 × (乗算記号)
    std::cout << "ispunct(\'\\xd7\', default C locale) returned "
              << std::boolalpha << (bool)std::ispunct(c) << '\n';
    std::setlocale(LC_ALL, "en_GB.iso88591");
    std::cout << "ispunct(\'\\xd7\', ISO-8859-1 locale) returned "
              << std::boolalpha << (bool)std::ispunct(c) << '\n';
}

出力例:

ispunct('\xd7', default C locale) returned false
ispunct('\xd7', ISO-8859-1 locale) returned true

関連項目

ロケールによって句読点文字として分類されるかどうかをチェックする
(関数テンプレート)
ワイド文字が句読点文字かどうかをチェックする
(関数)
HTMLタグ、属性、 タグ内のテキスト、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